package com.zjht.gmcc.bean.sms;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.util.InitParam;
import com.zjht.gmcc.bean.util.MyConstant;
import com.zjht.gmcc.bean.util.MyFormat;
import com.zjht.gmcc.bean.util.MyJDBC;
import com.zjht.gmcc.bean.util.MyParamUtil;
import com.zjht.gmcc.bean.util.MySession;

public class Task { 

	// 消息编码TaskCode 
	public static final String ZERODEPOT_HALL = "1"; // 厅零库存
	public static final String ZERODEPOT_HALLTOCITYPROVIDER = "2"; // 厅零库存，通知市平台
	public static final String ZERODEPOT_CITYPROVIDER = "3"; // 市平台零库存
	public static final String ZERODEPOT_CITYPROVIDERTOPROV = "4"; // 市平台零库存，通知省平台
	public static final String ZERODEPOT_PROVPROVIDER = "5"; // 省平台零库存
	public static final String ZERODEPOT_PROVPROVIDERTOVENDOR = "6";// 省平台零库存，通知厂家

	public static final String FILL_APPLY_TO_COUNTY = "11"; // 服务厅/市平台补货申请,请区审批
	public static final String FILL_APPLY_TO_HALL = "12"; // 市平台主动补货申请,请服务厅确认
	public static final String FILL_CANCEL_TO_CITYPROVIDER = "13"; // 市平台主动补货申请，经服务厅撤销后通知市平台
	public static final String FILL_AFFIRM_TO_CITYPROVIDER = "14"; // 市平台主动补货申请，经服务厅确认后通知市平台
	public static final String FILL_AUDIT_CANCEL_TO_HALL = "15"; // 区/县审批撤销，向服务厅发送消息
	public static final String FILL_AUDIT_CANCEL_TO_CITYPROVIDER = "16";// 区/县审批撤销，向市平台发送消息(用于主动补货)
	public static final String FILL_AUDIT_PASS_TO_HALL = "17"; // 区/县审批通过，向服务厅发送消息
	public static final String FILL_AUDIT_PASS_TO_CITYPROVIDER = "18"; // 区/县审批通过，通知市平台
	public static final String FILL_AUDIT_PASS_TO_CITYPROVIDER_SELF = "19"; // 区/县审批通过，通知市平台(主动补货)
	public static final String FILL_ORDER_CANCEL_TO_HALL = "20"; // 市平台撤销补货单，通知服务厅
	public static final String FILL_DISPOSE_TO_HALL = "30"; // 市平台补货配送，通知服务厅

	public static final String RETURN_AUDIT_TO_COUNTY = "41"; // 服务厅退货申请，请区审批
	public static final String RETURN_AUDIT_PASS_TO_HALL = "42"; // 区/县审批通过，向服务厅发送消息
	public static final String RETURN_AUDIT_PASS_TO_CITYPROVIDER = "43"; // 区/县审批通过，通知市平台
	public static final String RETURN_AFFIRM_TO_HALL = "44"; // 市平台确认退货的结果，通知服务厅
	public static final String RETURN_AUDIT_CANCEL_TO_HALL = "45"; // 区移动撤销退货，通知服务厅

	// 省公司相关报表短信
	public static final String PROVMOBILE_SALERATE_RPT = "201"; // 销量监控：每天发送短信，内容为：昨天全省的终端销售总量、销量前三名机型、销量前三名市公司、销量前三名服务厅的信息。
	public static final String PROVMOBILE_HALLSALERATE_RPT = "202"; // 服务厅销售监控：每天发送短信，内容为：单厅单机型昨天销量超过100台的对应机型名称、服务厅名称、所属平台名称。
	public static final String PROVMOBILE_ONSALE_RPT = "203"; // 上架率监控：每天发送短信，内容为：昨天库存机型数量低于在库机型60%的服务厅名称、所属平台名称
	public static final String PROVMOBILE_SALE_QUANTITY = "204"; // 某机型销售量：每天发送短信

	public static final String PROVMOBILE_G3_SALE_DAILY = "205"; // 省移动G3每日销售情况
	public static final String PROVMOBILE_G3_SALE_MONTH = "206"; // 省移动G3每月销售情况
	public static final String PROVMOBILE_G3_SALE_DAILY_PRODUCT = "207"; // 全省日销量超1000台的单款机型情况
	public static final String PROVMOBILE_G3_SALE_DAILY_PRODUCT_IN_AREA = "208"; // 地市日销量超300台的单款机型情况
	public static final String PROVMOBILE_G3_SALE_DAILY_CHANNEL = "209"; // 渠道网点日销售单款机型超50台的情况
	public static final String PROVMOBILE_G3_SALE_TARGET = "210"; // G3销量进度通报
	public static final String PROVMOBILE_G3_SALE_TARGET_VIP = "211"; // 发送给领导的G3销量进度通报
	
	public static final String PROVMOBILE_G3_ZD_VIP = "7002"; // 发送给领导的G3销量进度通报
	
	
	public static final String PROVMOBILE_SALE_DAILY_CITY = "212"; // 地市终端日销量通报
	public static final String PROVMOBILE_SALE_DAILY_CITY_VIP = "213"; // 发送给领导的地市终端日销量通报
	public static final String PROVMOBILE_MARKET_CITY = "214"; // 发送给领导的小众营销案销量预警

	public static final String CITYMOBILE_G3_SALE_DAILY = "251"; // 市移动G3每日销售情况
	public static final String CITYMOBILE_G3_SALE_MONTH = "252"; // 市移动G3每月销售情况
	public static final String CITYMOBILE_G3_SALE_DAILY_PRODUCT = "253"; // 市移动日销量超300台的单款机型情况
	public static final String CITYMOBILE_G3_SALE_DAILY_CHANNEL = "254"; // 市移动渠道网点日销售单款机型超50台的情况

	public static final String PROVMOBILE_PRODUCTWARN = "255"; // 省移动：终端限售/停售通知
	public static final String CITYMOBILE_PRODUCTWARN = "256"; // 市移动：终端限售/停售通知

	public static final String PROVMOBILE_PRODUCTWARN_CANCEL = "257"; // 省移动：终端限售/停售解禁通知
	public static final String CITYMOBILE_PRODUCTWARN_CANCEL = "258"; // 市移动：终端限售/停售解禁通知

	public static final String PROVMOBILE_DAILY_TD = "259"; // 省移动：TD手机销量前X名中增长率高于N%的机型
	public static final String PROVMOBILE_DAILY_TD_PRODUCTLEVEL = "260"; // 省移动：非AB类机型销量超过N台的TD手机
	public static final String PROVMOBILE_DAILY_CMMB = "261"; // 省移动：亚运CMMB销量

	public static final String PROVMOBILE_DAILY_SALE_SOMEPRODUCT = "262"; // 省移动：某些机型日销量日报
	public static final String PROVMOBILE_DAILY_SALE_SOMEPRODUCT_VIP = "263"; // 省移动VIP：某些机型日销量日报	

	public static final String PROVMOBILE_AGENT_ZD = "266"; //  终端公司代理机型日报
	public static final String PROVMOBILE_AGENT_ZD_VIP = "267"; // 发送给领导的终端公司代理机型日报

	public static final String PROVMOBILE_ZD = "264"; // 终端公司销量日报
	public static final String PROVMOBILE_ZD_VIP = "265"; // 发送给领导的 终端公司销量日报	
	
	public static final String PROVMOBILE_ZD_RETAIL = "268"; // 终端公司零售日报
	public static final String PROVMOBILE_ZD_RETAIL_VIP = "269"; // 发送给领导的 终端公司零售日报	
	
	public static final String PROVMOBILE_AGENT_ZD_SPEC = "270"; // 发送市场部经理和产品经理的终端公司代理机型日报
	public static final String PROVMOBILE_AGENT_ZD_CITY = "271"; // 发送市场部经理和产品经理的终端公司代理机型日报
	
	public static final String PRODUCTNOW = "221"; // 当前营销机型名称列表
	public static final String SALE_QUANTITY = "222"; // 根据机型查询销量

	public static final String MARKETING_PACKAUDIT = "901"; // 省产品室经理或市场部总经理
	public static final String MARKETING_PACKOK = "902"; // 省产品室科员2

	public static final String MARKETING_PROVINCEAUDIT = "910";// 省产品室经理或市场部总经理
	public static final String MARKETING_CITYADD = "911"; // 市移动
	public static final String MARKETING_CITYOK = "912"; // 省产品室科员2
	public static final String MARKETING_CITYAUDIT = "913"; // 省产品室经理或市场部总经理

	public static final String MARKETING_PROVINCE1 = "110"; // 全球通营销案模板发布
	public static final String MARKETING_PROVINCE2 = "120"; // 全品牌营销案模板发布
	public static final String CHOICE_OK = "130"; // 选型已经省副总审批

	// 手机短信允许发送的时间段
	public static final int SMSStartTime = 7; // 手机短信开始时间
	public static final int SMSEndTime = 20; // 手机短信结束时间

	// ZSMS启动时间
	public static Date CTMSStartTime = null;

	// 消息定义
	public static Map<String, String> hTaskDefineDesc = new HashMap<String, String>();// 消息内容：TaskDesc
	public static Map<String, String> hTaskDefineMenu = new HashMap<String, String>();// 消息菜单：MenuName`LinkFile
	public static Map<String, String> hTaskDefineReceiver = new HashMap<String, String>();// 消息接收人
	public static Map<String, Integer> hTaskDefineReceiverOrgaType = new HashMap<String, Integer>();// 消息接收组织类型
	public static ArrayList<String> arrTaskDefineNotBackUp = new ArrayList<String>();// 不需要备份的消息(DoBackUp为0)
	public static ArrayList<String> arrTaskDefineToClear = new ArrayList<String>();// 需要消除的消息(DoBackUp为2)
	public static ArrayList<String> arrTaskDefineSMS = new ArrayList<String>();// 需要发送手机短信(SMS为1)

	// TaskID与TaskCode对应
	// key:TaskID
	// value:TaskCode
	public static Map<String, String> hTaskHallIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
	public static Map<String, String> hTaskCountyMobileIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 区移动
	public static Map<String, String> hTaskCityMobileIDToCode = new HashMap<String, String>();// 市移动
	public static Map<String, String> hTaskProvMobileIDToCode = new HashMap<String, String>();// 省移动
	public static Map<String, String> hTaskCityProviderIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 市平台
	public static Map<String, String> hTaskProvProviderIDToCode = new HashMap<String, String>();// 省平台
	public static Map<String, String> hTaskVendorIDToCode = new HashMap<String, String>();// 厂家

	// 核心参数，用于根据消息内容删除消息或查找
	// key:TaskID
	// value:KeyWord，业务数据中的关键字段，如补货单号等
	public static Map<String, String> hTaskHallCore[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
	public static Map<String, String> hTaskCountyMobileCore[] = new HashMap[MyConstant.AREA_MAX];// 区移动
	public static Map<String, String> hTaskCityMobileCore = new HashMap<String, String>();// 市移动
	public static Map<String, String> hTaskProvMobileCore = new HashMap<String, String>();// 省移动
	public static Map<String, String> hTaskCityProviderCore[] = new HashMap[MyConstant.AREA_MAX];// 市平台
	public static Map<String, String> hTaskProvProviderCore = new HashMap<String, String>();// 省平台
	public static Map<String, String> hTaskVendorCore = new HashMap<String, String>();// 厂家

	// 用于网页显示
	// key:TaskID
	// value:MenuName`LinkFile`TaskDesc(已替换%1%等)``SenderOrgaName'SenderOperName`Date
	public static Map<String, String> hTaskHallDetail[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
	public static Map<String, String> hTaskCountyMobileDetail[] = new HashMap[MyConstant.AREA_MAX];// 区移动
	public static Map<String, String> hTaskCityMobileDetail = new HashMap<String, String>();// 市移动
	public static Map<String, String> hTaskProvMobileDetail = new HashMap<String, String>();// 省移动
	public static Map<String, String> hTaskCityProviderDetail[] = new HashMap[MyConstant.AREA_MAX];// 市平台
	public static Map<String, String> hTaskProvProviderDetail = new HashMap<String, String>();// 省平台
	public static Map<String, String> hTaskVendorDetail = new HashMap<String, String>();// 厂家

	// 接收人定义
	// key：TaskID
	// value：@DutyID或#OperCode或$strReceiverOrgaCode`@DutyID
	public static Map<String, String> hTaskHallReceiverDefine = new HashMap<String, String>();// 服务厅
	public static Map<String, String> hTaskCountyMobileReceiverDefine = new HashMap<String, String>();// 区移动
	public static Map<String, String> hTaskCityMobileReceiverDefine = new HashMap<String, String>();// 市移动
	public static Map<String, String> hTaskProvMobileReceiverDefine = new HashMap<String, String>();// 省移动
	public static Map<String, String> hTaskCityProviderReceiverDefine = new HashMap<String, String>();// 市平台
	public static Map<String, String> hTaskProvProviderReceiverDefine = new HashMap<String, String>();// 省平台
	public static Map<String, String> hTaskVendorReceiverDefine = new HashMap<String, String>();// 厂家

	// 实际接收人定义
	// key：TaskID
	// value：如果TaskReceiverDefine为@DutyID
	// 则： 已阅：$OrgaCode1,$OrgaCode2,
	// 已删：!OrgaCode1,!OrgaCode2,
	// OrgaCode状态可混合：!OrgaCode1,$OrgaCode2,
	// value：如果TaskReceiverDefine为$ReceiverOrgaCode`@DutyID或#OperCode
	// 则： 已阅：1
	public static Map<String, String> hTaskHallReceivers[] = new HashMap[MyConstant.AREA_MAX];// 服务厅：实际接收人
	public static Map<String, String> hTaskCountyMobileReceivers[] = new HashMap[MyConstant.AREA_MAX];// 区移动：接收人
	public static Map<String, String> hTaskCityMobileReceivers = new HashMap<String, String>();// 市移动：接收人
	public static Map<String, String> hTaskProvMobileReceivers = new HashMap<String, String>();// 省移动：接收人
	public static Map<String, String> hTaskCityProviderReceivers[] = new HashMap[MyConstant.AREA_MAX];// 市平台：接收人
	public static Map<String, String> hTaskProvProviderReceivers = new HashMap<String, String>();// 省平台：接收人
	public static Map<String, String> hTaskVendorReceivers = new HashMap<String, String>();// 厂家：接收人

	// 短信接收手机(如果TaskReceiver为DutyID)
	// key：OrgaCode@DutyID，其中DutyID为TaskDefine中IsSMS为1的DutyID
	// value：手机号码，多个号码使用#间隔，如：1380000000#13999999999#15800000000
	public static Map<String, String> hTaskHallTels[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
	public static Map<String, String> hTaskCountyMobileTels[] = new HashMap[MyConstant.AREA_MAX];// 区移动
	public static Map<String, String> hTaskCityMobileTels = new HashMap<String, String>();// 市移动
	public static Map<String, String> hTaskProvMobileTels = new HashMap<String, String>();// 省移动
	public static Map<String, String> hTaskCityProviderTels[] = new HashMap[MyConstant.AREA_MAX];// 市平台
	public static Map<String, String> hTaskProvProviderTels = new HashMap<String, String>();// 省平台
	public static Map<String, String> hTaskVendorTels = new HashMap<String, String>();// 厂家

	// 零库存产品列表，用于记录下一次零库存时是否需要提醒用户
	// key:OrgaCode
	// value:ProductName(多个机型，使用逗号间隔)
	public static Map<String, String> hZERODEPOT_HALL[] = new HashMap[MyConstant.AREA_MAX]; // 厅零库存
	public static Map<String, String> hZERODEPOT_CITYPROVIDER = new HashMap<String, String>(); // 市平台零库存
	public static Map<String, String> hZERODEPOT_PROVPROVIDER = new HashMap<String, String>(); // 省平台零库存
	public static Map<String, String> hZERODEPOT_VENDOR = new HashMap(); // 省平台零库存提醒厂家(key:厂家OrgaCode+省平台ShortName,Value:ProductName)

	// 当前零库存组织列表
	// key:OrgaCode
	public static ArrayList<String> arrZERODEPOT_HALL[] = new ArrayList[MyConstant.AREA_MAX]; // 厅零库存
	public static ArrayList<String> arrZERODEPOT_CITYPROVIDER = new ArrayList<String>(); // 市平台零库存
	public static ArrayList<String> arrZERODEPOT_PROVPROVIDER = new ArrayList<String>(); // 省平台零库存
	public static ArrayList<String> arrZERODEPOT_VENDOR = new ArrayList<String>(); // 省平台零库存提醒厂家(key:厂家OrgaCode+省平台ShortName)

	// 短信接收手机(如果TaskReceiver为#OperCode)
	public static Map<String, String> hTaskOperTels = new HashMap<String, String>();// 用户

	// 短信接收相关的DutyID，多个DutyID用,间隔，如：5300,5000,6300
	public static String strDutyListForSMS = "";

	// 如果TaskReceiver为#OperCode
	// 值：'OperCode1','OperCode2','OperCode3'
	public static String strOperListForSMS = "";

	// 补货审批用户手机列表
	// key：手机号码（不能包含多个号码）
	// value：OperCode`OrgaCode`张三
	// 说明：如果用户有多个手机号，则以一个手机号码为key，分开存储
	public static Map<String, String> hFillAuditListForSMS = new HashMap<String, String>();

	// 退货审批用户手机列表
	// key：手机号码（不能包含多个号码）
	// value：OperCode`OrgaCode`张三
	// 说明：如果用户有多个手机号，则以一个手机号码为key，分开存储
	public static Map<String, String> hReturnAuditListForSMS = new HashMap<String, String>();

	// 补货确认用户手机列表
	// key：手机号码（不能包含多个号码）
	// value：OperCode`OrgaCode`张三
	// 说明：如果用户有多个手机号，则以一个手机号码为key，分开存储
	public static Map<String, String> hFillAffirmListForSMS = new HashMap<String, String>();

	// 补货审批接收人（取自Task表的TaskReceiver字段）
	public static String strFillAuditTastReceiver = "";

	// 补货确认接收人（取自Task表的TaskReceiver字段）
	public static String strFillAffirmTastReceiver = "";

	// 退货审批接收人（取自Task表的TaskReceiver字段）
	public static String strReturnAuditTastReceiver = "";

	// public static int intZeroDepotReset=0;

	private static int intTaskID = 0;// TaskID
	private static boolean isReqAutoAuditFirst = true;// 是否第一次自动审批

	public static String Alerts[] = new String[10];// 临时紧急通知(用于系统维护和升级前停机通知)
	public static boolean AlertTypes[] = new boolean[10];// true:只有top提示，没有alert警告框；false：两者都有

	public static Calendar ReqAuditTime = Calendar.getInstance();// 补货自动审批计时

	/**
	 * 处理补货自动审批的消息
	 * @author dyh 2008-01-01
	 */
	public static void ReqAutoAudit() {
		
	}

	/**
	 * 初始化消息定义
	 * @author dyh 2008-01-01
	 */
	public static void initTaskDefine() {
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			hTaskDefineDesc.clear();
			hTaskDefineMenu.clear();
			hTaskDefineReceiver.clear();
			hTaskDefineReceiverOrgaType.clear();
			arrTaskDefineNotBackUp.clear();
			arrTaskDefineToClear.clear();
			arrTaskDefineSMS.clear();

			strDutyListForSMS = "";

			// DoBackup:0表示不备份，1表示必须使用程序删除，2表示定期备份并删除
			String strSQL = " SELECT TaskCode,TaskDesc,MenuName,LinkFile,TaskReceiver,ReceiverOrgaType,DoBackup,SMS FROM V_TaskDefine";
			PreparedStatement ps = myJDBC.prepareStatement(strSQL);
			ResultSet rs = ps.executeQuery();
			String strTaskCode = "";
			String strTaskDesc = "";
			String strMenuName = "";
			String strLinkFile = "";
			String strTaskReceiver = "";
			int intReceiverOrgaType = -1;
			String strDoBackup = "";
			String strSMS = "";
			String strTaskReceiverTemp[] = null;
			String strTemp = "";
			while (rs.next()) {
				strTaskCode = rs.getString("TaskCode");
				strTaskDesc = rs.getString("TaskDesc");
				strMenuName = rs.getString("MenuName");
				if (strMenuName == null)
					strMenuName = "--";
				strLinkFile = rs.getString("LinkFile");
				if (strLinkFile == null)
					strLinkFile = "--";
				strTaskReceiver = rs.getString("TaskReceiver");
				intReceiverOrgaType = rs.getInt("ReceiverOrgaType");
				strDoBackup = rs.getString("DoBackup");
				strSMS = rs.getString("SMS");

				hTaskDefineDesc.put(strTaskCode, strTaskDesc);
				hTaskDefineMenu.put(strTaskCode, strMenuName + "`" + strLinkFile);
				hTaskDefineReceiver.put(strTaskCode, strTaskReceiver);
				hTaskDefineReceiverOrgaType.put(strTaskCode, intReceiverOrgaType);
				if (strDoBackup.equals("0"))
					arrTaskDefineNotBackUp.add(strTaskCode);
				else if (strDoBackup.equals("2"))
					arrTaskDefineToClear.add(strTaskCode);

				// 插入短信审批接收人
				// 补货审批（区分公司）
				if (strTaskCode.equals(FILL_APPLY_TO_COUNTY))
					strFillAuditTastReceiver = strTaskReceiver;
				// 补货确认（服务厅）
				else if (strTaskCode.equals(FILL_APPLY_TO_HALL))
					strFillAffirmTastReceiver = strTaskReceiver;
				// 退货审批（区分公司）
				else if (strTaskCode.equals(RETURN_AUDIT_TO_COUNTY))
					strReturnAuditTastReceiver = strTaskReceiver;

				if (strSMS.equals("1")) {
					arrTaskDefineSMS.add(strTaskCode);

					// strTaskReceiver两种可能值：@DutyID、#OperCode
					strTaskReceiverTemp = strTaskReceiver.replaceAll("@", "").split(",");
					strTemp = "";
					for (int i = 0; i < strTaskReceiverTemp.length; i++) {
						// 如果是#OperCode，不插入
						if (strTaskReceiverTemp[i].indexOf("#") != -1) {
							strTemp = strTaskReceiverTemp[i].substring(1);

							if (strOperListForSMS.length() > 0) {
								if ((strOperListForSMS).indexOf(("'" + strTemp + "'")) == -1)
									strOperListForSMS += ",'" + strTemp + "'";
							} else
								strOperListForSMS = "'" + strTemp + "'";
						} else {
							strTemp = strTaskReceiverTemp[i];
							if (strDutyListForSMS.length() > 0) {
								if (("," + strDutyListForSMS + ",").indexOf(("," + strTemp + ",")) == -1)
									strDutyListForSMS += "," + strTemp;
							} else
								strDutyListForSMS = strTemp;
						}
					}
				}
			}
			InitialSMS();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 初始化手机短信接收号码
	 * @author dyh 2008-01-01
	 */
	public static void InitialSMS() {
		if (strDutyListForSMS.length() == 0 && strOperListForSMS.length() == 0)
			return;
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			String strSQL = "";
			PreparedStatement ps = null;
			ResultSet rs = null;

			if (strDutyListForSMS.length() > 0) {
				for (int i = 1; i < MyConstant.AREA_MAX; i++) {
					hTaskHallTels[i].clear();
					hTaskCountyMobileTels[i].clear();
					hTaskCityProviderTels[i].clear();
				}
				hTaskProvProviderTels.clear();
				hTaskCityMobileTels.clear();
				hTaskProvMobileTels.clear();
				hTaskVendorTels.clear();

				hFillAuditListForSMS.clear();// 补货审批手机用户
				hFillAffirmListForSMS.clear();// 补货确认手机用户
				hReturnAuditListForSMS.clear();// 退货确认手机用户

				strSQL = "select a.opername,a.opercode,c.orgacode,b.dutyid,a.telephone,c.areaid,c.orgatypeid from opers a,operspopedom b,organiza c "
						+ "where a.status='1' and c.status='1' and a.opercode=b.opercode and a.orgacode=c.orgacode and a.telephone is not null and b.dutyid in ("
						+ strDutyListForSMS + ")";

				ps = myJDBC.prepareStatement(strSQL);
				rs = ps.executeQuery();
				String strOperName = "";
				String strOperCode = "";
				String strOrgaCode = "";
				String strDutyID = "";
				String strTelePhone = "";
				int intOrgaTypeID = -1;
				int intAreaID = -1;
				String key = "";
				Map<String, String> hTels = new HashMap<String, String>();
				String strTelOK = "";
				while (rs.next()) {
					strOperName = rs.getString("opername");
					strOperCode = rs.getString("opercode");
					strOrgaCode = rs.getString("orgacode");
					strDutyID = rs.getString("dutyid");
					strTelePhone = rs.getString("telephone");
					intOrgaTypeID = rs.getInt("orgatypeid");
					if (strTelePhone.length() < 11)
						continue;

					intAreaID = rs.getInt("areaid");
					switch (intOrgaTypeID) {
						case MyConstant.ORGTYPE_HALL:
							hTels = hTaskHallTels[intAreaID];
							break;
						case MyConstant.ORGTYPE_COUNTYMOBILE:
							hTels = hTaskCountyMobileTels[intAreaID];
							break;
						case MyConstant.ORGTYPE_CITYPROVIDER:
							hTels = hTaskCityProviderTels[intAreaID];
							break;
						case MyConstant.ORGTYPE_PROVPROVIDER:
							hTels = hTaskProvProviderTels;
							break;
						case MyConstant.ORGTYPE_CITYMOBILE:
							hTels = hTaskCityMobileTels;
							break;
						case MyConstant.ORGTYPE_PROVMOBILE:
							hTels = hTaskProvMobileTels;
							break;
						case MyConstant.ORGTYPE_VENDOR:
							hTels = hTaskVendorTels;
					}
					key = strOrgaCode + "@" + strDutyID;

					String strTel = hTels.get(key);
					if (strTel == null || strTel.length() == 0) {
						hTels.put(key, strTelePhone.replaceAll(",", "#"));
					} else {
						strTelOK = strTel;
						String strTels[] = strTelePhone.split(",");
						for (int i = 0; i < strTels.length; i++) {
							if (("#" + strTelOK + "#").indexOf("#" + strTels[i] + "#") == -1)
								strTelOK += "#" + strTels[i];
						}
						hTels.put(key, strTelOK);
					}

					// 短信审批手机列表
					if (strFillAuditTastReceiver.length() > 0 && strFillAuditTastReceiver.indexOf("@" + strDutyID) != -1) {
						String strTels[] = strTelePhone.split(",");
						for (int i = 0; i < strTels.length; i++) {
							if (hFillAuditListForSMS.containsKey(strTels[i]))// 必须去除不同用户的相同手机号码
							{
								hFillAuditListForSMS.remove(strTels[i]);
								continue;
							}
							hFillAuditListForSMS.put(strTels[i], strOperCode + "`" + strOrgaCode + "`" + strOperName);
						}
					}
					if (strFillAffirmTastReceiver.length() > 0 && strFillAffirmTastReceiver.indexOf("@" + strDutyID) != -1) {
						String strTels[] = strTelePhone.split(",");
						for (int i = 0; i < strTels.length; i++) {
							if (hFillAffirmListForSMS.containsKey(strTels[i]))// 必须去除不同用户的相同手机号码
							{
								hFillAffirmListForSMS.remove(strTels[i]);
								continue;
							}
							hFillAffirmListForSMS.put(strTels[i], strOperCode + "`" + strOrgaCode + "`" + strOperName);
						}
					}
					if (strReturnAuditTastReceiver.length() > 0 && strReturnAuditTastReceiver.indexOf("@" + strDutyID) != -1) {
						String strTels[] = strTelePhone.split(",");
						for (int i = 0; i < strTels.length; i++) {
							if (hReturnAuditListForSMS.containsKey(strTels[i]))// 必须去除不同用户的相同手机号码
							{
								hReturnAuditListForSMS.remove(strTels[i]);
								continue;
							}
							hReturnAuditListForSMS.put(strTels[i], strOperCode + "`" + strOrgaCode + "`" + strOperName);
						}
					}
				}
			}
			if (strOperListForSMS.length() > 0) {
				hTaskOperTels.clear();

				strSQL = "select opercode,telephone from opers " + "where status='1' and telephone is not null and opercode in (" + strOperListForSMS
						+ ")";

				ps = myJDBC.prepareStatement(strSQL);
				rs = ps.executeQuery();
				String strOperCode = "";
				String strTelePhone = "";
				while (rs.next()) {
					strOperCode = rs.getString("opercode");
					strTelePhone = rs.getString("telephone");
					if (strTelePhone.length() < 11)
						continue;
					if (strTelePhone.indexOf(",") != -1)
						strTelePhone = strTelePhone.replaceAll(",", "#");
					hTaskOperTels.put(strOperCode, strTelePhone);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 更新手机短信接收号码
	 * @author dyh 2008-01-01
	 * @param strNewTel 新手机号(多号码可用逗号间隔)
	 * @param strOldTel 旧手机号(多号码可用逗号间隔)
	 * @param strDutyID 接收人DutyID
	 * @param strOrgaCode 接收人组织编码
	 * @param strOperCode 接收人编码
	 * @param strOperName 接收人姓名
	 */
	public static void UpdateSMSReceiver(String strNewTel, String strOldTel, String strDutyID, String strOrgaCode, String strOperCode,
			String strOperName) {
		if (strNewTel == null || strOldTel == null || (strOldTel.length() < 11 && strNewTel.length() < 11) || strOldTel.equals(strNewTel))
			return;
		if (strDutyListForSMS.length() == 0 && strOperListForSMS.length() == 0)
			return;
		try {
			if (strDutyListForSMS.length() > 0 && ("," + strDutyListForSMS + ",").indexOf("," + strDutyID + ",") != -1) {
				int intReceiverAreaID = MyParamUtil.getOrgaAreaID(strOrgaCode);
				int intOrgaType = MyParamUtil.getOrgaTypeID(strOrgaCode);
				Map<String, String> hTaskTels = new HashMap<String, String>();
				switch (intOrgaType) {
					case MyConstant.ORGTYPE_PROVMOBILE:
						hTaskTels = hTaskProvMobileTels;
						break;
					case MyConstant.ORGTYPE_CITYMOBILE:
						hTaskTels = hTaskCityMobileTels;
						break;
					case MyConstant.ORGTYPE_COUNTYMOBILE:
						hTaskTels = hTaskCountyMobileTels[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_HALL:
						hTaskTels = hTaskHallTels[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_PROVPROVIDER:
						hTaskTels = hTaskProvProviderTels;
						break;
					case MyConstant.ORGTYPE_CITYPROVIDER:
						hTaskTels = hTaskCityProviderTels[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_VENDOR:
						hTaskTels = hTaskVendorTels;
						break;
					default:
						return;
				}
				MyJDBC myJDBC = null;
				try {
					myJDBC = new MyJDBC();
					String sql = "select a.telephone from opers a,operspopedom b,organiza c "
							+ "where a.status='1' and c.status='1' and a.opercode=b.opercode and a.orgacode=c.orgacode and a.telephone is not null and b.dutyid =? and c.orgacode=?";
					PreparedStatement ps = myJDBC.prepareStatement(sql);
					ps.setInt(1, Integer.parseInt(strDutyID));
					ps.setString(2, strOrgaCode);
					ResultSet rs = ps.executeQuery();
					String _strNewTel = "";
					String strTemp = "";
					while (rs.next()) {
						strTemp = rs.getString(1);
						if (_strNewTel.length() == 0) {
							if (strTemp.indexOf(",") != -1)
								strTemp = strTemp.replaceAll(",", "#");
							_strNewTel = strTemp;
						} else {
							String strTels[] = strTemp.split(",");
							for (int i = 0; i < strTels.length; i++) {
								if (("#" + _strNewTel + "#").indexOf("#" + strTels[i] + "#") == -1)
									_strNewTel += "#" + strTels[i];
							}
						}
					}
					String key = strOrgaCode + "@" + strDutyID;
					if (_strNewTel.length() >= 11)
						hTaskTels.put(key, _strNewTel);
					else
						hTaskTels.remove(key);
				} catch (Exception ex) {
				} finally {
					MyJDBC.close(myJDBC);
				}

				// 更新短信审批手机列表
				// 区分需要删除的号码和需要新增的号码
				ArrayList<String> strDel = new ArrayList<String>();
				ArrayList<String> strAdd = new ArrayList<String>();
				if (strOldTel.length() >= 11 && strNewTel.length() >= 11) {
					String strOldTemp[] = strOldTel.split(",");
					String strNewTemp[] = strNewTel.split(",");
					boolean found = false;
					for (int i = 0, j = 0; i < strOldTemp.length; i++) {
						found = false;
						for (j = 0; j < strNewTemp.length; j++) {
							if (strOldTemp[i].equals(strNewTemp[j])) {
								found = true;
								break;
							}
						}
						if (!found)
							strDel.add(strOldTemp[i]);
					}
					for (int i = 0, j = 0; i < strNewTemp.length; i++) {
						found = false;
						for (j = 0; j < strOldTemp.length; j++) {
							if (strOldTemp[j].equals(strNewTemp[i])) {
								found = true;
								break;
							}
						}
						if (!found)
							strAdd.add(strNewTemp[i]);
					}
				} else if (strOldTel.length() < 11)// 全部新增
				{
					String strNewTemp[] = strNewTel.split(",");
					for (int i = 0; i < strNewTemp.length; i++) {
						strAdd.add(strNewTemp[i]);
					}
				} else// 全部删除
				{
					String strOldTemp[] = strNewTel.split(",");
					for (int i = 0; i < strOldTemp.length; i++) {
						strDel.add(strOldTemp[i]);
					}
				}

				if (strFillAuditTastReceiver.length() > 0 && strFillAuditTastReceiver.indexOf("@" + strDutyID) != -1) {
					String s = null;
					for (int i = 0; i < strDel.size(); i++) {
						s = hFillAuditListForSMS.get(strDel.get(i));
						if (s != null && s.indexOf(strOperCode + "`" + strOrgaCode + "`") != -1) {
							hFillAuditListForSMS.remove(strDel.get(i));
						}
					}
					for (int i = 0; i < strAdd.size(); i++) {
						if (hFillAuditListForSMS.containsKey(strAdd.get(i)))// 必须去除不同用户的相同手机号码
						{
							hFillAuditListForSMS.remove(strAdd.get(i));
							continue;
						}
						hFillAuditListForSMS.put(strAdd.get(i), strOperCode + "`" + strOrgaCode + "`" + strOperName);
					}
				}
				if (strFillAffirmTastReceiver.length() > 0 && strFillAffirmTastReceiver.indexOf("@" + strDutyID) != -1) {
					String s = null;
					for (int i = 0; i < strDel.size(); i++) {
						s = hFillAffirmListForSMS.get(strDel.get(i));
						if (s != null && s.indexOf(strOperCode + "`" + strOrgaCode + "`") != -1) {
							hFillAffirmListForSMS.remove(strDel.get(i));
						}
					}
					for (int i = 0; i < strAdd.size(); i++) {
						if (hFillAffirmListForSMS.containsKey(strAdd.get(i)))// 必须去除不同用户的相同手机号码
						{
							hFillAffirmListForSMS.remove(strAdd.get(i));
							continue;
						}
						hFillAffirmListForSMS.put(strAdd.get(i), strOperCode + "`" + strOrgaCode + "`" + strOperName);
					}
				}
				if (strReturnAuditTastReceiver.length() > 0 && strReturnAuditTastReceiver.indexOf("@" + strDutyID) != -1) {
					String s = null;
					for (int i = 0; i < strDel.size(); i++) {
						s = hReturnAuditListForSMS.get(strDel.get(i));
						if (s != null && s.indexOf(strOperCode + "`" + strOrgaCode + "`") != -1) {
							hReturnAuditListForSMS.remove(strDel.get(i));
						}
					}
					for (int i = 0; i < strAdd.size(); i++) {
						if (hReturnAuditListForSMS.containsKey(strAdd.get(i)))// 必须去除不同用户的相同手机号码
						{
							hReturnAuditListForSMS.remove(strAdd.get(i));
							continue;
						}
						hReturnAuditListForSMS.put(strAdd.get(i), strOperCode + "`" + strOrgaCode + "`" + strOperName);
					}
				}
			}
			if (strOperListForSMS.length() > 0 && (strOperListForSMS).indexOf("'" + strOperCode + "'") != -1) {
				if (strNewTel.length() > 0 && strNewTel.indexOf(",") != -1)
					strNewTel = strNewTel.replaceAll(",", "#");
				if (strNewTel.length() == 0)
					hTaskOperTels.remove(strOperCode);
				else {
					hTaskOperTels.put(strOperCode, strNewTel);
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 消息插入到Task列表
	 * @author dyh 2008-01-01
	 * @param strTaskCode Task编码
	 * @param strTaskParam 替换参数，可为null；如果是多个，可用逗号间隔
	 * @param strKeyWord 关键字，用于以后删除消息用,如果为空，则表示无须手工删除消息
	 * @param strSenderOrgaName 发送人组织名称
	 * @param strSenderOperName 发送人姓名
	 */
	public static void InsertTask(String strTaskCode, String strTaskParam, String strKeyWord, String strSenderOrgaName, String strSenderOperName) {
		InsertTask(null, strTaskCode, strTaskParam, strKeyWord, strSenderOrgaName, strSenderOperName);
	}

	/**
	 * 消息插入到Task列表
	 * @author dyh 2008-01-01
	 * @param strReceiverOrgaCode 消息接收组织(市平台、区移动和服务厅必须指定strReceiverOrgaCode)
	 * @param strTaskCode Task编码
	 * @param strTaskParam 替换参数，可为null；如果是多个，可用逗号间隔
	 * @param strKeyWord 关键字，用于以后删除消息用,如果为空，则表示无须手工删除消息
	 * @param strSenderOrgaName 发送人组织名称
	 * @param strSenderOperName 发送人姓名
	 */
	public static void InsertTask(String strReceiverOrgaCode, String strTaskCode, String strTaskParam, String strKeyWord, String strSenderOrgaName,
			String strSenderOperName) {

		try {
			// 获取消息定义模板参数
			if (hTaskDefineReceiverOrgaType == null || hTaskDefineReceiverOrgaType.size() == 0 || hTaskDefineReceiver == null
					|| hTaskDefineReceiver.size() == 0) {
				initTaskDefine();
			}

			if (hTaskDefineReceiverOrgaType == null || hTaskDefineReceiverOrgaType.size() == 0 || hTaskDefineReceiver == null
					|| hTaskDefineReceiver.size() == 0)
				return;

			int intOrgaType = MyFormat.formatInt(Task.hTaskDefineReceiverOrgaType.get(strTaskCode));
			if (intOrgaType <= 0)
				return;

			int intReceiverAreaID = -1;

			// 市平台、区移动和服务厅必须指定strReceiverOrgaCode
			if (MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType || MyConstant.ORGTYPE_COUNTYMOBILE == intOrgaType
					|| MyConstant.ORGTYPE_HALL == intOrgaType) {
				if (strReceiverOrgaCode != null) {
					intReceiverAreaID = MyParamUtil.getOrgaAreaID(strReceiverOrgaCode);
					if (intReceiverAreaID == -1)
						return;
					InsertTaskOK(intReceiverAreaID, strReceiverOrgaCode, intOrgaType, strTaskCode, strTaskParam, strKeyWord, strSenderOrgaName,
							strSenderOperName);
				} else {
					return;
				}
			} else
				InsertTaskOK(intReceiverAreaID, strReceiverOrgaCode, intOrgaType, strTaskCode, strTaskParam, strKeyWord, strSenderOrgaName,
						strSenderOperName);
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(InsertTask) error");
		}
	}

	/**
	 * 消息插入到Task列表
	 * @author dyh 2008-01-01
	 * @param intReceiverAreaID 接收人地市ID（-1代表空，0为广东省，其他为各地市，最大是21）
	 * @param strReceiverOrgaCode 消息接收组织，如果为null，表示所有符合OrgaType的组织具有DutyID的用户
	 * @param strOrgaType 消息接收组织类型
	 * @param strTaskCode Task编码
	 * @param strTaskParam 替换参数，可为null；如果是多个，可用逗号间隔
	 * @param strKeyWord 关键字，用于以后删除消息用,如果为空，则表示无须手工删除消息
	 * @param strSenderOrgaName 发送人组织名称
	 * @param strSenderOperName 发送人姓名
	 */
	private static void InsertTaskOK(int intReceiverAreaID, String strReceiverOrgaCode, int intOrgaType, String strTaskCode, String strTaskParam,
			String strKeyWord, String strSenderOrgaName, String strSenderOperName) {
		try {
			if (intOrgaType <= 0)
				return;

			// 市平台、区移动和服务厅必须指定intReceiverOrgaCode
			if (MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType || MyConstant.ORGTYPE_COUNTYMOBILE == intOrgaType
					|| MyConstant.ORGTYPE_HALL == intOrgaType) {
				if (intReceiverAreaID <= 0 || intReceiverAreaID >= MyConstant.AREA_MAX)
					return;
			}

			// 消息接收人定义
			String strTaskDefineReceiver = hTaskDefineReceiver.get(strTaskCode);
			if (strTaskDefineReceiver == null || strTaskDefineReceiver.length() == 0)
				return;

			// 消息菜单
			String strTaskDefineMenu = hTaskDefineMenu.get(strTaskCode);
			if (strTaskDefineMenu == null || strTaskDefineMenu.length() == 0)
				return;

			// 消息内容
			String strTaskDefineDesc = hTaskDefineDesc.get(strTaskCode);
			if (strTaskDefineDesc == null || strTaskDefineDesc.length() == 0)
				return;

			Map<String, String> hTaskIDToCode = new HashMap<String, String>();
			Map<String, String> hTaskCore = new HashMap<String, String>();
			Map<String, String> hTaskDetail = new HashMap<String, String>();
			Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();

			switch (intOrgaType) {
				case MyConstant.ORGTYPE_PROVMOBILE:
					hTaskIDToCode = hTaskProvMobileIDToCode;
					hTaskCore = hTaskProvMobileCore;
					hTaskDetail = hTaskProvMobileDetail;
					hTaskReceiverDefine = hTaskProvMobileReceiverDefine;
					break;
				case MyConstant.ORGTYPE_CITYMOBILE:
					hTaskIDToCode = hTaskCityMobileIDToCode;
					hTaskCore = hTaskCityMobileCore;
					hTaskDetail = hTaskCityMobileDetail;
					hTaskReceiverDefine = hTaskCityMobileReceiverDefine;
					break;
				case MyConstant.ORGTYPE_COUNTYMOBILE:
					hTaskIDToCode = hTaskCountyMobileIDToCode[intReceiverAreaID];
					hTaskCore = hTaskCountyMobileCore[intReceiverAreaID];
					hTaskDetail = hTaskCountyMobileDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCountyMobileReceiverDefine;
					break;
				case MyConstant.ORGTYPE_HALL:
					hTaskIDToCode = hTaskHallIDToCode[intReceiverAreaID];
					hTaskCore = hTaskHallCore[intReceiverAreaID];
					hTaskDetail = hTaskHallDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskHallReceiverDefine;
					break;
				case MyConstant.ORGTYPE_PROVPROVIDER:
					hTaskIDToCode = hTaskProvProviderIDToCode;
					hTaskCore = hTaskProvProviderCore;
					hTaskDetail = hTaskProvProviderDetail;
					hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
					break;
				case MyConstant.ORGTYPE_CITYPROVIDER:
					hTaskIDToCode = hTaskCityProviderIDToCode[intReceiverAreaID];
					hTaskCore = hTaskCityProviderCore[intReceiverAreaID];
					hTaskDetail = hTaskCityProviderDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
					break;
				case MyConstant.ORGTYPE_VENDOR:
					hTaskIDToCode = hTaskVendorIDToCode;
					hTaskCore = hTaskVendorCore;
					hTaskDetail = hTaskVendorDetail;
					hTaskReceiverDefine = hTaskVendorReceiverDefine;
				default:
					return;
			}
			// 消息参数
			if (strTaskParam.endsWith("`"))
				strTaskParam = strTaskParam.substring(0, strTaskParam.length() - 1);
			if (strTaskParam.indexOf("`") >= 0) {
				String strTaskParams[] = strTaskParam.split("`");
				for (int i = 0; i < strTaskParams.length; i++) {
					strTaskDefineDesc = strTaskDefineDesc.replaceAll("%" + (i + 1) + "%", strTaskParams[i]);
				}
			} else
				strTaskDefineDesc = strTaskDefineDesc.replaceAll("%1%", strTaskParam);

			// 消息接收人
			if (strTaskDefineReceiver.endsWith(","))
				strTaskDefineReceiver = strTaskDefineReceiver.substring(0, strTaskDefineReceiver.length() - 1);
			if (strTaskDefineReceiver.indexOf(",") >= 0) {
				String strTaskDefineReceivers[] = strTaskDefineReceiver.split(",");
				for (int i = 0; i < strTaskDefineReceivers.length; i++) {
					InsertTaskDone(intOrgaType, intReceiverAreaID, hTaskIDToCode, hTaskCore, hTaskDetail, hTaskReceiverDefine, strReceiverOrgaCode,
							strTaskCode, strTaskDefineReceivers[i], strTaskDefineMenu, strKeyWord, strTaskDefineDesc, strSenderOrgaName,
							strSenderOperName);
				}
			} else {
				InsertTaskDone(intOrgaType, intReceiverAreaID, hTaskIDToCode, hTaskCore, hTaskDetail, hTaskReceiverDefine, strReceiverOrgaCode,
						strTaskCode, strTaskDefineReceiver, strTaskDefineMenu, strKeyWord, strTaskDefineDesc, strSenderOrgaName, strSenderOperName);
			}
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(InsertTaskOK) error");
		}
	}

	/**
	 * 发送手机短信
	 * @author dyh 2008-01-01
	 * @param strOrgaType 接收人组织类型
	 * @param intReceiverAreaID 接收人地市ID
	 * @param strReceiverOrgaCode 接收人组织编码
	 * @param strTaskReceiver @DutyID或#OperCode
	 * @param strContent 短信内容
	 */
	

	/**
	 * 新增消息
	 * @author dyh 2008-01-01
	 * @param strOrgaType 消息接收组织类型
	 * @param intReceiverAreaID 接收人地市ID（-1代表空，0为广东省，其他为各地市，最大是21）
	 * @param hTaskIDToCode
	 * @param hTaskCore
	 * @param hTaskDetail
	 * @param hTaskReceiverDefine
	 * @param strReceiverOrgaCode 消息接收人组织类型
	 * @param strTaskCode
	 * @param strTaskReceiver
	 * @param strTaskMenu 用于首面超链接(MenuName`LinkFile)
	 * @param strKeyWord 关键字，用于以后删除消息用,如果为空，则表示无须手工删除消息
	 * @param strTaskDesc 消息内容(已经替换%1%)
	 * @param strSenderOrgaName 发送人组织名称
	 * @param strSenderOperName 发送人姓名
	 */
	private static void InsertTaskDone(int intOrgaType, int intReceiverAreaID, Map<String, String> hTaskIDToCode, Map<String, String> hTaskCore,
			Map<String, String> hTaskDetail, Map<String, String> hTaskReceiverDefine, String strReceiverOrgaCode, String strTaskCode,
			String strTaskReceiver, String strTaskMenu, String strKeyWord, String strTaskDesc, String strSenderOrgaName, String strSenderOperName) {
		try {
			intTaskID++;

			hTaskIDToCode.put(intTaskID + "", strTaskCode);

			// 是否为零库存
			boolean isZeroDepot = (strTaskCode.equals(ZERODEPOT_HALL) || strTaskCode.equals(ZERODEPOT_HALLTOCITYPROVIDER)
					|| strTaskCode.equals(ZERODEPOT_CITYPROVIDER) || strTaskCode.equals(ZERODEPOT_CITYPROVIDERTOPROV)
					|| strTaskCode.equals(ZERODEPOT_PROVPROVIDER) || strTaskCode.equals(ZERODEPOT_PROVPROVIDERTOVENDOR));

			// value:TaskCode`@DutyID或#OperCode`MenuName`LinkFile`TaskParam
			// KeyWord为关键字，用于以后删除消息用,如果为空，则表示无须手工删除消息。零库存的hTaskCore为“TRUE”或“FALSE”，表示是否要发送短信，无须登记
			if (strKeyWord != null && strKeyWord.length() > 0 && !isZeroDepot)
				hTaskCore.put(intTaskID + "", strKeyWord);

			// MenuName`LinkFile`TaskDesc(%1%已经替换成实际值)`Sender`Date
			hTaskDetail.put(intTaskID + "", strTaskMenu + "`" + strTaskDesc + "`" + strSenderOrgaName + "`" + strSenderOperName + "`"
					+ MyFormat.getDateFormat(Calendar.getInstance().getTime()));
			hTaskReceiverDefine.put(intTaskID + "", (strReceiverOrgaCode == null || strReceiverOrgaCode.length() == 0) ? strTaskReceiver : "$"
					+ strReceiverOrgaCode + "`" + strTaskReceiver);

			// 限制短信发送时间(20:00-8:00禁止发短信)，以及是否允许发短信。
		
			// System.out.println(strKeyWord+",OrgaCode="+strReceiverOrgaCode+",strTaskReceiver="+strTaskReceiver+",strTaskDesc="+strTaskDesc);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看消息
	 * @author dyh 2008-01-01
	 * @param session
	 * @param strTaskID
	 * @return 是否成功
	 */
	public static boolean ViewTask(HttpSession session, String strTaskID) {
		try {
			if (session == null)
				return false;

			int intOrgaType = MySession.getOrgtype(session);
			if (intOrgaType == -1)
				return false;
			String strOrgaCode = MySession.getOrgcode(session);
			String strDutyID = String.valueOf(MySession.getDutyid(session));
			String strOperCode = MySession.getUsercode(session);
			String strReceiverAreaID = String.valueOf(MySession.getAreaid(session));

			if (strDutyID.length() == 0 || strOperCode.length() == 0 || strReceiverAreaID.length() == 0)
				return false;

			int intReceiverAreaID = -1;
			if (MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType || MyConstant.ORGTYPE_COUNTYMOBILE == intOrgaType
					|| MyConstant.ORGTYPE_HALL == intOrgaType) {
				try {
					intReceiverAreaID = Integer.parseInt(strReceiverAreaID);
				} catch (Exception ex2) {

				}
				if (intReceiverAreaID <= 0 || intReceiverAreaID >= MyConstant.AREA_MAX)
					return false;
			}

			Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();
			Map<String, String> hTaskReceivers = new HashMap<String, String>();
			switch (intOrgaType) {
				case MyConstant.ORGTYPE_PROVMOBILE:
					hTaskReceiverDefine = hTaskProvMobileReceiverDefine;
					hTaskReceivers = hTaskProvMobileReceivers;
					break;
				case MyConstant.ORGTYPE_CITYMOBILE:
					hTaskReceiverDefine = hTaskCityMobileReceiverDefine;
					hTaskReceivers = hTaskCityMobileReceivers;
					break;
				case MyConstant.ORGTYPE_COUNTYMOBILE:
					hTaskReceiverDefine = hTaskCountyMobileReceiverDefine;
					hTaskReceivers = hTaskCountyMobileReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_HALL:
					hTaskReceiverDefine = hTaskHallReceiverDefine;
					hTaskReceivers = hTaskHallReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_PROVPROVIDER:
					hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
					hTaskReceivers = hTaskProvProviderReceivers;
					break;
				case MyConstant.ORGTYPE_CITYPROVIDER:
					hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
					hTaskReceivers = hTaskCityProviderReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_VENDOR:
					hTaskReceiverDefine = hTaskVendorReceiverDefine;
					hTaskReceivers = hTaskVendorReceivers;
					break;
				default:
					return false;
			}
			String strReceiverDefine = hTaskReceiverDefine.get(strTaskID);
			if (strReceiverDefine == null || strReceiverDefine.length() == 0)
				return false;

			String strReceiver = "";

			// strReceiverDefine是否只有DutyID
			boolean ReceiverisDutyID = false;

			// 接收人是否为用户本人
			if (("@" + strDutyID).equals(strReceiverDefine)) {
				ReceiverisDutyID = true;
			} else if (!("$" + strOrgaCode + "`@" + strDutyID).equals(strReceiverDefine) && !("#" + strOperCode).equals(strReceiverDefine))
				return false;

			boolean isRead = false;
			if (ReceiverisDutyID) {
				strReceiver = hTaskReceivers.get(strTaskID);
				if (strReceiver == null || strReceiver.length() == 0 || ("@" + strOrgaCode + ",").equals(strReceiver)// 已阅读
						|| ("!" + strOrgaCode + ",").equals(strReceiver))// 已删除
					return false;
				hTaskReceivers.put(strTaskID, strReceiver + "@" + strOrgaCode + ",");
				isRead = true;
			} else {
				if ("1".equals(strReceiver))// 找到已读
					return false;
				else {
					hTaskReceivers.put(strTaskID, "1");
					isRead = true;
				}
			}
			if (isRead) {
				// strFirstTaskList=strFirstTaskList.replaceAll(strTaskID+"=0=",strTaskID+"=1=");
				// int intNew=Integer.parseInt(strMsgCount.substring(0,strMsgCount.indexOf(',')));
				// int intRead=Integer.parseInt(strMsgCount.substring(strMsgCount.indexOf(',')+1,strMsgCount.length()));
				// intNew--;
				// intRead++;
				// return intNew+","+intRead+"`"+strFirstTaskList;
				return TaskMsg(session);
			} else
				return false;
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(ViewTask) error");
			return false;
		}
	}

	/**
	 * 根据关键字结束消息
	 * @author dyh 2008-01-01
	 * @param strKeyWord 关键字
	 * @param strOrgaCode 消息组织编码
	 */
	public static void CompleteTask(String strKeyWord, String strOrgaCode) {
		try {
			if (strKeyWord != null && strKeyWord.length() > 0 && strOrgaCode != null && strOrgaCode.length() > 0) {
				int intOrgaType = MyParamUtil.getOrgaTypeID(strOrgaCode);
				if (intOrgaType <= 0)
					return;

				int intReceiverAreaID = MyParamUtil.getOrgaAreaID(strOrgaCode);
				if (intReceiverAreaID == -1)
					return;

				CompleteTask(strKeyWord, intOrgaType, intReceiverAreaID);
			}
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(CompleteTask) error");
		}
	}

	/**
	 * 根据关键字结束消息
	 * @author dyh 2008-01-01
	 * @param strKeyWord
	 * @param strOrgaType
	 * @param strReceiverAreaID
	 */
	public static void CompleteTask(String strKeyWord, int intOrgaType, int intReceiverAreaID) {
		try {
			if (intReceiverAreaID <= 0 || intReceiverAreaID >= MyConstant.AREA_MAX)
				return;
			if (strKeyWord != null && strKeyWord.length() > 0 && intOrgaType > 0) {
				Map<String, String> hTaskIDToCode = new HashMap<String, String>();
				Map<String, String> hTaskCore = new HashMap<String, String>();
				Map<String, String> hTaskDetail = new HashMap<String, String>();
				Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();
				Map<String, String> hTaskReceivers = new HashMap<String, String>();

				switch (intOrgaType) {
					case MyConstant.ORGTYPE_PROVMOBILE:
						hTaskIDToCode = hTaskProvMobileIDToCode;
						hTaskCore = hTaskProvMobileCore;
						hTaskDetail = hTaskProvMobileDetail;
						hTaskReceiverDefine = hTaskProvMobileReceiverDefine;
						hTaskReceivers = hTaskProvMobileReceivers;
						break;
					case MyConstant.ORGTYPE_CITYMOBILE:
						hTaskIDToCode = hTaskCityMobileIDToCode;
						hTaskCore = hTaskCityMobileCore;
						hTaskDetail = hTaskCityMobileDetail;
						hTaskReceiverDefine = hTaskCityMobileReceiverDefine;
						hTaskReceivers = hTaskCityMobileReceivers;
						break;
					case MyConstant.ORGTYPE_COUNTYMOBILE:
						hTaskIDToCode = hTaskCountyMobileIDToCode[intReceiverAreaID];
						hTaskCore = hTaskCountyMobileCore[intReceiverAreaID];
						hTaskDetail = hTaskCountyMobileDetail[intReceiverAreaID];
						hTaskReceiverDefine = hTaskCountyMobileReceiverDefine;
						hTaskReceivers = hTaskCountyMobileReceivers[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_HALL:
						hTaskIDToCode = hTaskHallIDToCode[intReceiverAreaID];
						hTaskCore = hTaskHallCore[intReceiverAreaID];
						hTaskDetail = hTaskHallDetail[intReceiverAreaID];
						hTaskReceiverDefine = hTaskHallReceiverDefine;
						hTaskReceivers = hTaskHallReceivers[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_PROVPROVIDER:
						hTaskIDToCode = hTaskProvProviderIDToCode;
						hTaskCore = hTaskProvProviderCore;
						hTaskDetail = hTaskProvProviderDetail;
						hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
						hTaskReceivers = hTaskProvProviderReceivers;
						break;
					case MyConstant.ORGTYPE_CITYPROVIDER:
						hTaskIDToCode = hTaskCityProviderIDToCode[intReceiverAreaID];
						hTaskCore = hTaskCityProviderCore[intReceiverAreaID];
						hTaskDetail = hTaskCityProviderDetail[intReceiverAreaID];
						hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
						hTaskReceivers = hTaskCityProviderReceivers[intReceiverAreaID];
						break;
					case MyConstant.ORGTYPE_VENDOR:
						hTaskIDToCode = hTaskVendorIDToCode;
						hTaskCore = hTaskVendorCore;
						hTaskDetail = hTaskVendorDetail;
						hTaskReceiverDefine = hTaskVendorReceiverDefine;
						hTaskReceivers = hTaskVendorReceivers;
						break;
					default:
						return;
				}

				if (hTaskCore.containsValue(strKeyWord)) {
					Iterator<Entry<String, String>> iter = hTaskCore.entrySet().iterator();
					while (iter.hasNext()) {
						Entry<String, String> entry = iter.next();
						String key = entry.getKey();
						String val = entry.getValue();
						if (val.equals(strKeyWord)) {
							hTaskCore.remove(key);
							hTaskDetail.remove(key);
							hTaskReceiverDefine.remove(key);
							hTaskIDToCode.remove(key);
							hTaskReceivers.remove(key);
							break;
						}
					}
				}
			}
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(CompleteTask) error");
		}
	}

	/**
	 * 我的消息列表
	 * @author dyh 2008-01-01
	 * @param intReceiverAreaID
	 * @param arrTaskListNew
	 * @param arrTaskListRead
	 * @param strOrgaType
	 * @param strOrgaCode
	 * @param strDutyID
	 * @param strOperCode
	 */
	public static void TaskList(int intReceiverAreaID, ArrayList<String> arrTaskListNew, ArrayList<String> arrTaskListRead, int intOrgaType,
			String strOrgaCode, String strDutyID, String strOperCode) {
		try {
			if (intOrgaType <= 0)
				return;

			// 市平台、区移动和服务厅必须指定intReceiverAreaID
			if (MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType || MyConstant.ORGTYPE_COUNTYMOBILE == intOrgaType
					|| MyConstant.ORGTYPE_HALL == intOrgaType) {
				if (intReceiverAreaID <= 0 || intReceiverAreaID >= MyConstant.AREA_MAX)
					return;
			}

			Map<String, String> hTaskDetail = new HashMap<String, String>();
			Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();
			Map<String, String> hTaskReceivers = new HashMap<String, String>();
			switch (intOrgaType) {
				case MyConstant.ORGTYPE_PROVMOBILE:
					hTaskDetail = hTaskProvMobileDetail;
					hTaskReceiverDefine = hTaskProvMobileReceiverDefine;
					hTaskReceivers = hTaskProvMobileReceivers;
					break;
				case MyConstant.ORGTYPE_CITYMOBILE:
					hTaskDetail = hTaskCityMobileDetail;
					hTaskReceiverDefine = hTaskCityMobileReceiverDefine;
					hTaskReceivers = hTaskCityMobileReceivers;
					break;
				case MyConstant.ORGTYPE_COUNTYMOBILE:
					hTaskDetail = hTaskCountyMobileDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCountyMobileReceiverDefine;
					hTaskReceivers = hTaskCountyMobileReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_HALL:
					hTaskDetail = hTaskHallDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskHallReceiverDefine;
					hTaskReceivers = hTaskHallReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_PROVPROVIDER:
					hTaskDetail = hTaskProvProviderDetail;
					hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
					hTaskReceivers = hTaskProvProviderReceivers;
					break;
				case MyConstant.ORGTYPE_CITYPROVIDER:
					hTaskDetail = hTaskCityProviderDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
					hTaskReceivers = hTaskCityProviderReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_VENDOR:
					hTaskDetail = hTaskVendorDetail;
					hTaskReceiverDefine = hTaskVendorReceiverDefine;
					hTaskReceivers = hTaskVendorReceivers;
					break;
				default:
					return;
			}
			Iterator<Entry<String, String>> iter = hTaskReceiverDefine.entrySet().iterator();
			String key = null;
			String val = "";
			String strReceiver = "";

			boolean isNew = false;
			boolean isMine = true;
			boolean ReceiverisDutyID = false;

			arrTaskListNew.clear();// 新消息
			arrTaskListRead.clear();// 已读消息

			ArrayList<String> arrTaskListNewTemp = new ArrayList<String>();// 新消息
			ArrayList<String> arrTaskListReadTemp = new ArrayList<String>();// 已读消息

			while (iter.hasNext()) {
				Entry<String, String> entry = iter.next();
				key = entry.getKey();

				// val：@DutyID或#OperCode或$strReceiverOrgaCode=@DutyID
				val = entry.getValue();

				isMine = true;
				isNew = false;
				ReceiverisDutyID = false;

				// 接收人是否为用户本人
				if (("@" + strDutyID).equals(val)) {
					ReceiverisDutyID = true;
				} else if (!("$" + strOrgaCode + "`@" + strDutyID).equals(val) && !("#" + strOperCode).equals(val))
					continue;

				if (isMine) {
					strReceiver = hTaskReceivers.get(key);
					if (strReceiver == null || strReceiver.length() == 0) {
						isNew = true;
					} else {
						if (ReceiverisDutyID)// $OrgaCode为已读，!OrgaCode为已删
						{
							if (strReceiver.indexOf(strOrgaCode) >= 0) {
								if (strReceiver.indexOf("$" + strOrgaCode) < 0)// 没有找到已读
									continue;
							} else
								isNew = true;
						} else// 1表示已读
						{
							if (!"1".equals(strReceiver))// 没有找到已读
								continue;
						}
					}
					// int ikey=Integer.parseInt(key.toString());
					if (isNew) {
						// arrTaskListNew.add(key+"`0`"+hTaskDetail.get(key));
						arrTaskListNewTemp.add(key);
					} else {
						// arrTaskListRead.add(key+"`1`"+hTaskDetail.get(key));
						arrTaskListReadTemp.add(key);
					}
				}
			}
			Collections.sort(arrTaskListNewTemp);
			Collections.sort(arrTaskListReadTemp);

			for (int i = 0; i < arrTaskListNewTemp.size(); i++) {
				key = arrTaskListNewTemp.get(i);
				arrTaskListNew.add(key + "`0`" + hTaskDetail.get(key));
			}

			for (int i = 0; i < arrTaskListReadTemp.size(); i++) {
				key = arrTaskListReadTemp.get(i);
				arrTaskListRead.add(key + "`0`" + hTaskDetail.get(key));
			}

		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(TaskList) error");
		}
	}

	/**
	 * 首页及TOP消息提示，用于暂存于Session中(intCount为获取消息的数量)
	 * @author dyh 2008-01-01
	 * @param session
	 * @return 是否成功
	 */
	public static boolean TaskMsg(HttpSession session) {
		try {

			if (session == null)
				return false;

			int intOrgaType = MySession.getOrgtype(session);
			if (intOrgaType == -1)
				return false;
			String strOrgaCode = MySession.getOrgcode(session);
			String strDutyID = String.valueOf(MySession.getDutyid(session));
			String strOperCode = MySession.getUsercode(session);
			String strReceiverAreaID = String.valueOf(MySession.getAreaid(session));

			if (strDutyID.length() == 0 || strOperCode.length() == 0 || strReceiverAreaID.length() == 0)
				return false;

			int intReceiverAreaID = -1;
			if (MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType || MyConstant.ORGTYPE_COUNTYMOBILE == intOrgaType
					|| MyConstant.ORGTYPE_HALL == intOrgaType) {
				try {
					intReceiverAreaID = Integer.parseInt(strReceiverAreaID);
				} catch (Exception ex2) {

				}
				if (intReceiverAreaID <= 0 || intReceiverAreaID >= MyConstant.AREA_MAX)
					return false;
			}

			Map<String, String> hTaskDetail = new HashMap<String, String>();
			Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();
			Map<String, String> hTaskReceivers = new HashMap<String, String>();
			switch (intOrgaType) {
				case MyConstant.ORGTYPE_PROVMOBILE:
					hTaskDetail = hTaskProvMobileDetail;
					hTaskReceiverDefine = hTaskProvMobileReceiverDefine;
					hTaskReceivers = hTaskProvMobileReceivers;
					break;
				case MyConstant.ORGTYPE_CITYMOBILE:
					hTaskDetail = hTaskCityMobileDetail;
					hTaskReceiverDefine = hTaskCityMobileReceiverDefine;
					hTaskReceivers = hTaskCityMobileReceivers;
					break;
				case MyConstant.ORGTYPE_COUNTYMOBILE:
					hTaskDetail = hTaskCountyMobileDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCountyMobileReceiverDefine;
					hTaskReceivers = hTaskCountyMobileReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_HALL:
					hTaskDetail = hTaskHallDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskHallReceiverDefine;
					hTaskReceivers = hTaskHallReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_PROVPROVIDER:
					hTaskDetail = hTaskProvProviderDetail;
					hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
					hTaskReceivers = hTaskProvProviderReceivers;
					break;
				case MyConstant.ORGTYPE_CITYPROVIDER:
					hTaskDetail = hTaskCityProviderDetail[intReceiverAreaID];
					hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
					hTaskReceivers = hTaskCityProviderReceivers[intReceiverAreaID];
					break;
				case MyConstant.ORGTYPE_VENDOR:
					hTaskDetail = hTaskVendorDetail;
					hTaskReceiverDefine = hTaskVendorReceiverDefine;
					hTaskReceivers = hTaskVendorReceivers;
					break;
				default:
					return false;
			}
			int intNew = 0;// 新消息
			int intRead = 0;// 已读消息
			String key = null;
			String val = "";
			String strReceiver = "";
			String strFirstTastList = "";
			boolean isNew = false;
			boolean isMine = true;
			boolean ReceiverisDutyID = false;

			int intFirstTaskListsNew[] = new int[MyConstant.TASK_FIRSTLISTCOUNT];// 首页
			int intFirstTaskListsRead[] = new int[MyConstant.TASK_FIRSTLISTCOUNT];// 首页
			Iterator<Entry<String, String>> iter = hTaskReceiverDefine.entrySet().iterator();

			while (iter.hasNext()) {
				Entry<String, String> entry = iter.next();
				key = entry.getKey();

				// val：@DutyID或#OperCode或$strReceiverOrgaCode`@DutyID
				val = entry.getValue();

				isMine = true;
				isNew = false;
				ReceiverisDutyID = false;

				// 接收人是否为用户本人
				if (("@" + strDutyID).equals(val)) {
					ReceiverisDutyID = true;
				} else if (!("$" + strOrgaCode + "`@" + strDutyID).equals(val) && !("#" + strOperCode).equals(val))
					continue;

				if (isMine) {
					strReceiver = hTaskReceivers.get(key);
					if (strReceiver == null || strReceiver.length() == 0) {
						isNew = true;
					} else {
						if (ReceiverisDutyID)// $OrgaCode为已读，!OrgaCode为已删
						{
							if (strReceiver.indexOf(strOrgaCode) >= 0) {
								if (strReceiver.indexOf("$" + strOrgaCode) < 0)// 没有找到已读
									continue;
							} else
								isNew = true;
						} else// 1表示已读
						{
							if (!"1".equals(strReceiver))// 没有找到已读
								continue;
						}
					}
					int ikey = Integer.parseInt(key);

					if (isNew) {
						intNew++;
						SortTaskMsg(intFirstTaskListsNew, ikey);
					} else {
						intRead++;
						SortTaskMsg(intFirstTaskListsRead, ikey);
					}
				}
			}
			int i = 0;
			// 用^间隔
			// TaskID=阅读状态=TaskCode=MenuName=LinkFile=TaskDesc(已替换%1%等)=SenderOrga=SenderOper=Date
			for (; i < intNew && i < intFirstTaskListsNew.length; i++) {
				strFirstTastList += intFirstTaskListsNew[i] + "`0`" + hTaskDetail.get(intFirstTaskListsNew[i] + "") + "^";
			}

			for (int j = 0, remain = 0; j < intRead && j < intFirstTaskListsRead.length && remain < (intFirstTaskListsRead.length - i); j++) {
				if (intFirstTaskListsRead[j] == 0)
					break;
				strFirstTastList += intFirstTaskListsRead[j] + "`1`" + hTaskDetail.get(intFirstTaskListsRead[j] + "") + "^";
				remain++;
			}
			if (strFirstTastList.endsWith("^"))
				strFirstTastList = strFirstTastList.substring(0, strFirstTastList.length() - 1);

			session.setAttribute(MySession.TASK_MSGCOUNT, intNew + "," + intRead);
			session.setAttribute(MySession.TASK_FIRSTTASKLIST, strFirstTastList);
			return true;

		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(TaskMsg) error");
			return false;
		}
	}

	/**
	 * 新插入TaskID，进行排序
	 * @author dyh 2008-01-01
	 * @param TaskMsgs
	 * @param key
	 */
	private static void SortTaskMsg(int TaskMsgs[], int key) {
		for (int i = 0; i < TaskMsgs.length; i++) {
			if (key > TaskMsgs[i]) {
				for (int j = TaskMsgs.length - 2; j >= i; j--) {
					TaskMsgs[j + 1] = TaskMsgs[j];
				}
				TaskMsgs[i] = key;
				break;
			}
		}
	}

	/**
	 * 清空消息
	 * @author dyh 2008-01-01
	 */
	public static void ResetTask() {
		for (int i = 1; i < MyConstant.AREA_MAX; i++) {
			hTaskHallIDToCode[i].clear();
			hTaskHallCore[i].clear();
			hTaskHallDetail[i].clear();
			hTaskHallReceivers[i].clear();

			hTaskCountyMobileIDToCode[i].clear();
			hTaskCountyMobileCore[i].clear();
			hTaskCountyMobileDetail[i].clear();
			hTaskCountyMobileReceivers[i].clear();

			hTaskCityProviderIDToCode[i].clear();
			hTaskCityProviderCore[i].clear();
			hTaskCityProviderDetail[i].clear();
			hTaskCityProviderReceivers[i].clear();
		}

		hTaskHallReceiverDefine.clear();
		hTaskCountyMobileReceiverDefine.clear();
		hTaskCityProviderReceiverDefine.clear();

		hTaskCityMobileIDToCode.clear();
		hTaskCityMobileCore.clear();
		hTaskCityMobileDetail.clear();
		hTaskCityMobileReceiverDefine.clear();
		hTaskCityMobileReceivers.clear();

		hTaskProvMobileIDToCode.clear();
		hTaskProvMobileCore.clear();
		hTaskProvMobileDetail.clear();
		hTaskProvMobileReceiverDefine.clear();
		hTaskProvMobileReceivers.clear();

		hTaskProvProviderIDToCode.clear();
		hTaskProvProviderCore.clear();
		hTaskProvProviderDetail.clear();
		hTaskProvProviderReceiverDefine.clear();
		hTaskProvProviderReceivers.clear();

		hTaskVendorIDToCode.clear();
		hTaskVendorCore.clear();
		hTaskVendorDetail.clear();
		hTaskVendorReceiverDefine.clear();
		hTaskVendorReceivers.clear();
	}

	/**
	 * 备份消息(是否删除无用的消息)
	 * @author dyh 2008-01-01
	 * @param isDelTask
	 */
	public static void BackupTask(boolean isDelTask) {

		try {
			MyJDBC myJDBC = null;
			try {
				myJDBC = new MyJDBC();
				String strSQL = "DELETE TASKLIST";
				PreparedStatement ps = myJDBC.prepareStatement(strSQL);
				ps.execute();
			} catch (Exception ee) {
				ee.printStackTrace();
			} finally {
				MyJDBC.close(myJDBC);
			}

			ArrayList<String> delTask = null;// 无用的消息

			// 省移动
			if (isDelTask)
				delTask = new ArrayList<String>();
			BackupTaskDone((isDelTask ? delTask : null), hTaskProvMobileIDToCode, 0, MyConstant.ORGTYPE_PROVMOBILE, hTaskProvMobileCore,
					hTaskProvMobileDetail, hTaskProvMobileReceiverDefine, hTaskProvMobileReceivers);
			if (isDelTask)
				DelTask(delTask, hTaskProvMobileIDToCode, 0, MyConstant.ORGTYPE_PROVMOBILE, hTaskProvMobileCore, hTaskProvMobileDetail,
						hTaskProvMobileReceiverDefine, hTaskProvMobileReceivers);

			// 市移动
			if (isDelTask)
				delTask = new ArrayList<String>();
			BackupTaskDone((isDelTask ? delTask : null), hTaskCityMobileIDToCode, 0, MyConstant.ORGTYPE_CITYMOBILE, hTaskCityMobileCore,
					hTaskCityMobileDetail, hTaskCityMobileReceiverDefine, hTaskCityMobileReceivers);
			if (isDelTask)
				DelTask(delTask, hTaskCityMobileIDToCode, 0, MyConstant.ORGTYPE_CITYMOBILE, hTaskCityMobileCore, hTaskCityMobileDetail,
						hTaskCityMobileReceiverDefine, hTaskCityMobileReceivers);

			// 区移动
			int i = 1;
			for (; i < MyConstant.AREA_MAX; i++) {
				if (isDelTask)
					delTask = new ArrayList<String>();
				BackupTaskDone((isDelTask ? delTask : null), hTaskCountyMobileIDToCode[i], i, MyConstant.ORGTYPE_COUNTYMOBILE,
						hTaskCountyMobileCore[i], hTaskCountyMobileDetail[i], hTaskCountyMobileReceiverDefine, hTaskCountyMobileReceivers[i]);
				if (isDelTask)
					DelTask(delTask, hTaskCountyMobileIDToCode[i], i, MyConstant.ORGTYPE_COUNTYMOBILE, hTaskCountyMobileCore[i],
							hTaskCountyMobileDetail[i], hTaskCountyMobileReceiverDefine, hTaskCountyMobileReceivers[i]);
			}

			// 服务厅
			for (i = 1; i < MyConstant.AREA_MAX; i++) {
				if (isDelTask)
					delTask = new ArrayList<String>();
				BackupTaskDone((isDelTask ? delTask : null), hTaskHallIDToCode[i], i, MyConstant.ORGTYPE_HALL, hTaskHallCore[i], hTaskHallDetail[i],
						hTaskHallReceiverDefine, hTaskHallReceivers[i]);
				if (isDelTask)
					DelTask(delTask, hTaskHallIDToCode[i], i, MyConstant.ORGTYPE_HALL, hTaskHallCore[i], hTaskHallDetail[i], hTaskHallReceiverDefine,
							hTaskHallReceivers[i]);
			}

			// 省平台
			if (isDelTask)
				delTask = new ArrayList<String>();
			BackupTaskDone((isDelTask ? delTask : null), hTaskProvProviderIDToCode, 0, MyConstant.ORGTYPE_PROVPROVIDER, hTaskProvProviderCore,
					hTaskProvProviderDetail, hTaskProvProviderReceiverDefine, hTaskProvProviderReceivers);
			if (isDelTask)
				DelTask(delTask, hTaskProvProviderIDToCode, 0, MyConstant.ORGTYPE_PROVPROVIDER, hTaskProvProviderCore, hTaskProvProviderDetail,
						hTaskProvProviderReceiverDefine, hTaskProvProviderReceivers);

			// 市平台
			for (i = 1; i < MyConstant.AREA_MAX; i++) {
				if (isDelTask)
					delTask = new ArrayList<String>();
				BackupTaskDone((isDelTask ? delTask : null), hTaskCityProviderIDToCode[i], i, MyConstant.ORGTYPE_CITYPROVIDER,
						hTaskCityProviderCore[i], hTaskCityProviderDetail[i], hTaskCityProviderReceiverDefine, hTaskCityProviderReceivers[i]);
				if (isDelTask)
					DelTask(delTask, hTaskCityProviderIDToCode[i], i, MyConstant.ORGTYPE_CITYPROVIDER, hTaskCityProviderCore[i],
							hTaskCityProviderDetail[i], hTaskCityProviderReceiverDefine, hTaskCityProviderReceivers[i]);
			}
			// 厂家
			if (isDelTask)
				delTask = new ArrayList<String>();
			BackupTaskDone((isDelTask ? delTask : null), hTaskVendorIDToCode, 0, MyConstant.ORGTYPE_VENDOR, hTaskVendorCore, hTaskVendorDetail,
					hTaskVendorReceiverDefine, hTaskVendorReceivers);
			if (isDelTask)
				DelTask(delTask, hTaskVendorIDToCode, 0, MyConstant.ORGTYPE_VENDOR, hTaskVendorCore, hTaskVendorDetail, hTaskVendorReceiverDefine,
						hTaskVendorReceivers);

		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 备份消息(取出无用的消息)
	 * @author dyh 2008-01-01
	 * @param delTask
	 * @param hTaskIDToCode
	 * @param intAreaID
	 * @param strOrgaType
	 * @param hTaskCore
	 * @param hTaskDetail
	 * @param hTaskReceiverDefine
	 * @param hTaskReceivers
	 */
	private static void BackupTaskDone(ArrayList<String> delTask, Map<String, String> hTaskIDToCode, int intAreaID, int intOrgaType,
			Map<String, String> hTaskCore, Map<String, String> hTaskDetail, Map<String, String> hTaskReceiverDefine,
			Map<String, String> hTaskReceivers) {
		if (hTaskIDToCode == null || hTaskIDToCode.size() == 0 || hTaskCore == null || hTaskDetail == null || hTaskDetail.size() == 0
				|| hTaskReceiverDefine == null || hTaskReceiverDefine.size() == 0 || hTaskReceivers == null)
			return;
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			String strSQL = " INSERT INTO TaskList(TASKID,TASKCODE,AREAID,ORGATYPE,TASKCORE,TASKDETAIL,TASKRECEIVERDEFINE,TASKRECEIVERS,BACKUPDATE)"
					+ "VALUES(?,?,?,?,?,?,?,?,SYSDATE)";
			PreparedStatement ps = myJDBC.prepareStatement(strSQL);

			String strTaskID = "";
			String strTaskCode = "";
			String strTaskCore = null;
			String strTaskDetail = "";
			String strTaskReceiverDefine = "";
			String strTaskReceivers = null;
			String key = null;
			// String val = null;
			Iterator<Entry<String, String>> iter = hTaskIDToCode.entrySet().iterator();

			Calendar now = Calendar.getInstance();
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
			while (iter.hasNext()) {
				Entry<String, String> entry = iter.next();
				key = entry.getKey();
				if (key == null)
					continue;
				strTaskID = key;
				if (strTaskID.length() == 0)
					continue;

				strTaskReceivers = hTaskReceivers.get(key);

				strTaskCode = entry.getValue();
				if (strTaskCode == null || strTaskCode.length() == 0)
					continue;

				strTaskDetail = hTaskDetail.get(key);
				if (strTaskDetail == null || strTaskDetail.length() == 0)
					continue;
				String strTime = strTaskDetail.substring(strTaskDetail.length() - 16);

				if (strTaskCode.length() == 0 || arrTaskDefineNotBackUp.contains(strTaskCode)
						|| (arrTaskDefineToClear.contains(strTaskCode) && ("1".equals(strTaskReceivers)// 已读的不需要备份的消息
						|| ((now.getTime().getTime() - df.parse(strTime).getTime()) / (60 * 60 * 1000) > 12))))// 超过12小时的消息
				{
					// 不需要备份的消息
					if (delTask != null)
						delTask.add(key);
					continue;

				}

				strTaskReceiverDefine = hTaskReceiverDefine.get(key);
				if (strTaskReceiverDefine == null || strTaskReceiverDefine.length() == 0)
					continue;
				strTaskCore = hTaskCore.get(key);
				ps.setString(1, strTaskID);
				ps.setString(2, strTaskCode);
				ps.setInt(3, intAreaID);
				ps.setInt(4, intOrgaType);
				ps.setString(5, strTaskCore);
				ps.setString(6, strTaskDetail);
				ps.setString(7, strTaskReceiverDefine);
				ps.setString(8, strTaskReceivers);
				ps.executeUpdate();
			}
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 删除无用的消息
	 * @author dyh 2008-01-01
	 * @param delTask
	 * @param hTaskIDToCode
	 * @param intAreaID
	 * @param strOrgaType
	 * @param hTaskCore
	 * @param hTaskDetail
	 * @param hTaskReceiverDefine
	 * @param hTaskReceivers
	 */
	private static void DelTask(ArrayList<String> delTask, Map<String, String> hTaskIDToCode, int intAreaID, int intOrgaType,
			Map<String, String> hTaskCore, Map<String, String> hTaskDetail, Map<String, String> hTaskReceiverDefine,
			Map<String, String> hTaskReceivers) {
		try {
			if (delTask != null && delTask.size() > 0) {
				for (int i = 0; i < delTask.size(); i++) {
					hTaskIDToCode.remove(delTask.get(i));
					hTaskCore.remove(delTask.get(i));
					hTaskDetail.remove(delTask.get(i));
					hTaskReceiverDefine.remove(delTask.get(i));
					hTaskReceivers.remove(delTask.get(i));
				}
			}
		} catch (Exception e) {
			// e.printStackTrace();
			System.err.println("Task.java(DelTask) error");
		}
	}

	/**
	 * 恢复消息
	 * @author dyh 2008-01-01
	 */
	public static void RestoreTask() {
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			// TaskID与TaskCode对应
			// key:TaskID
			// value:TaskCode
			Map<String, String> hhTaskHallIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
			Map<String, String> hhTaskCountyMobileIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 区移动
			Map<String, String> hhTaskCityMobileIDToCode = new HashMap<String, String>();// 市移动
			Map<String, String> hhTaskProvMobileIDToCode = new HashMap<String, String>();// 省移动
			Map<String, String> hhTaskCityProviderIDToCode[] = new HashMap[MyConstant.AREA_MAX];// 市平台
			Map<String, String> hhTaskProvProviderIDToCode = new HashMap<String, String>();// 省平台
			Map<String, String> hhTaskVendorIDToCode = new HashMap<String, String>();// 厂家

			// 核心参数，用于根据消息内容删除消息或查找
			// key:TaskID
			// value:KeyWord，业务数据中的关键字段，如补货单号等
			Map<String, String> hhTaskHallCore[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
			Map<String, String> hhTaskCountyMobileCore[] = new HashMap[MyConstant.AREA_MAX];// 区移动
			Map<String, String> hhTaskCityMobileCore = new HashMap<String, String>();// 市移动
			Map<String, String> hhTaskProvMobileCore = new HashMap<String, String>();// 省移动
			Map<String, String> hhTaskCityProviderCore[] = new HashMap[MyConstant.AREA_MAX];// 市平台
			Map<String, String> hhTaskProvProviderCore = new HashMap<String, String>();// 省平台
			Map<String, String> hhTaskVendorCore = new HashMap<String, String>();// 厂家

			// 用于网页显示
			// key:TaskID
			// value:MenuName`LinkFile`TaskDesc(已替换%1%等)`Sender`Date
			Map<String, String> hhTaskHallDetail[] = new HashMap[MyConstant.AREA_MAX];// 服务厅
			Map<String, String> hhTaskCountyMobileDetail[] = new HashMap[MyConstant.AREA_MAX];// 区移动
			Map<String, String> hhTaskCityMobileDetail = new HashMap<String, String>();// 市移动
			Map<String, String> hhTaskProvMobileDetail = new HashMap<String, String>();// 省移动
			Map<String, String> hhTaskCityProviderDetail[] = new HashMap[MyConstant.AREA_MAX];// 市平台
			Map<String, String> hhTaskProvProviderDetail = new HashMap<String, String>();// 省平台
			Map<String, String> hhTaskVendorDetail = new HashMap<String, String>();// 厂家

			// 接收人定义
			// key：TaskID
			// value：@DutyID或#OperCode或$strReceiverOrgaCode`@DutyID
			Map<String, String> hhTaskHallReceiverDefine = new HashMap<String, String>();// 服务厅
			Map<String, String> hhTaskCountyMobileReceiverDefine = new HashMap<String, String>();// 区移动
			Map<String, String> hhTaskCityMobileReceiverDefine = new HashMap<String, String>();// 市移动
			Map<String, String> hhTaskProvMobileReceiverDefine = new HashMap<String, String>();// 省移动
			Map<String, String> hhTaskCityProviderReceiverDefine = new HashMap<String, String>();// 市平台
			Map<String, String> hhTaskProvProviderReceiverDefine = new HashMap<String, String>();// 省平台
			Map<String, String> hhTaskVendorReceiverDefine = new HashMap<String, String>();// 厂家

			// 实际接收人定义
			// key：TaskID
			// value：如果TaskReceiverDefine为@DutyID
			// 则： 已阅：$OrgaCode1,$OrgaCode2,
			// 已删：!OrgaCode1,!OrgaCode2,
			// OrgaCode状态可混合：!OrgaCode1,$OrgaCode2,
			// value：如果TaskReceiverDefine为$ReceiverOrgaCode`@DutyID或#OperCode
			// 则： 已阅：1
			Map<String, String> hhTaskHallReceivers[] = new HashMap[MyConstant.AREA_MAX];// 服务厅：实际接收人
			Map<String, String> hhTaskCountyMobileReceivers[] = new HashMap[MyConstant.AREA_MAX];// 区移动：接收人
			Map<String, String> hhTaskCityMobileReceivers = new HashMap<String, String>();// 市移动：接收人
			Map<String, String> hhTaskProvMobileReceivers = new HashMap<String, String>();// 省移动：接收人
			Map<String, String> hhTaskCityProviderReceivers[] = new HashMap[MyConstant.AREA_MAX];// 市平台：接收人
			Map<String, String> hhTaskProvProviderReceivers = new HashMap<String, String>();// 省平台：接收人
			Map<String, String> hhTaskVendorReceivers = new HashMap<String, String>();// 厂家：接收人

			for (int i = 1; i < MyConstant.AREA_MAX; i++) {
				hhTaskHallIDToCode[i] = new HashMap<String, String>();
				hhTaskHallCore[i] = new HashMap<String, String>();
				hhTaskHallDetail[i] = new HashMap<String, String>();
				hhTaskHallReceivers[i] = new HashMap<String, String>();

				hhTaskCountyMobileIDToCode[i] = new HashMap<String, String>();
				hhTaskCountyMobileCore[i] = new HashMap<String, String>();
				hhTaskCountyMobileDetail[i] = new HashMap<String, String>();
				hhTaskCountyMobileReceivers[i] = new HashMap<String, String>();

				hhTaskCityProviderIDToCode[i] = new HashMap<String, String>();
				hhTaskCityProviderCore[i] = new HashMap<String, String>();
				hhTaskCityProviderDetail[i] = new HashMap<String, String>();
				hhTaskCityProviderReceivers[i] = new HashMap<String, String>();
			}

			// TASKID,TASKCODE,AREAID,ORGATYPE,TASKCORE,TASKDETAIL,TASKRECEIVERDEFINE,TASKRECEIVERS,BACKUPDATE
			String strSQL = "SELECT * FROM TaskList ORDER BY TASKID,ORGATYPE,TASKCODE";
			PreparedStatement ps = myJDBC.prepareStatement(strSQL);
			ResultSet rs = ps.executeQuery();
			int iTaskID = 0;

			String strTaskCode = "";
			int intAreaID = 0;
			int intOrgaType = -1;
			String strTaskCore = null;
			String strTaskDetail = "";
			String strTaskReceiverDefine = "";
			String strTaskReceivers = null;
			String strTaskID = "";

			while (rs.next()) {
				strTaskCode = rs.getString("TASKCODE");
				intAreaID = rs.getInt("AREAID");
				intOrgaType = rs.getInt("ORGATYPE");
				strTaskCore = rs.getString("TASKCORE");
				strTaskDetail = rs.getString("TASKDETAIL");
				strTaskReceiverDefine = rs.getString("TASKRECEIVERDEFINE");
				strTaskReceivers = rs.getString("TASKRECEIVERS");

				if (strTaskCode == null || strTaskDetail == null || strTaskReceiverDefine == null || strTaskCode.length() == 0
						|| strTaskDetail.length() == 0 || strTaskReceiverDefine.length() == 0 || intAreaID < 0 || intAreaID >= MyConstant.AREA_MAX)
					continue;

				iTaskID++;
				strTaskID = iTaskID + "";
				switch (intOrgaType) {
					case MyConstant.ORGTYPE_PROVMOBILE:
						hhTaskProvMobileIDToCode.put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskProvMobileCore.put(strTaskID, strTaskCore);
						hhTaskProvMobileDetail.put(strTaskID, strTaskDetail);
						hhTaskProvMobileReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskProvMobileReceivers.put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_CITYMOBILE:
						hhTaskCityMobileIDToCode.put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskCityMobileCore.put(strTaskID, strTaskCore);
						hhTaskCityMobileDetail.put(strTaskID, strTaskDetail);
						hhTaskCityMobileReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskCityMobileReceivers.put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_COUNTYMOBILE:
						hhTaskCountyMobileIDToCode[intAreaID].put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskCountyMobileCore[intAreaID].put(strTaskID, strTaskCore);
						hhTaskCountyMobileDetail[intAreaID].put(strTaskID, strTaskDetail);
						hhTaskCountyMobileReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskCountyMobileReceivers[intAreaID].put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_HALL:
						hhTaskHallIDToCode[intAreaID].put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskHallCore[intAreaID].put(strTaskID, strTaskCore);
						hhTaskHallDetail[intAreaID].put(strTaskID, strTaskDetail);
						hhTaskHallReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskHallReceivers[intAreaID].put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_PROVPROVIDER:
						hhTaskProvProviderIDToCode.put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskProvProviderCore.put(strTaskID, strTaskCore);
						hhTaskProvProviderDetail.put(strTaskID, strTaskDetail);
						hhTaskProvProviderReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskProvProviderReceivers.put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_CITYPROVIDER:
						hhTaskCityProviderIDToCode[intAreaID].put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskCityProviderCore[intAreaID].put(strTaskID, strTaskCore);
						hhTaskCityProviderDetail[intAreaID].put(strTaskID, strTaskDetail);
						hhTaskCityProviderReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskCityProviderReceivers[intAreaID].put(strTaskID, strTaskReceivers);
						break;
					case MyConstant.ORGTYPE_VENDOR:
						hhTaskVendorIDToCode.put(strTaskID, strTaskCode);
						if (strTaskCore != null && strTaskCore.length() != 0)
							hhTaskVendorCore.put(strTaskID, strTaskCore);
						hhTaskVendorDetail.put(strTaskID, strTaskDetail);
						hhTaskVendorReceiverDefine.put(strTaskID, strTaskReceiverDefine);
						if (strTaskReceivers != null && strTaskReceivers.length() != 0)
							hhTaskVendorReceivers.put(strTaskID, strTaskReceivers);
						break;
				}
			}
			if (iTaskID > 0) {
				ResetTask();

				hTaskHallIDToCode = hhTaskHallIDToCode;
				hTaskCountyMobileIDToCode = hhTaskCountyMobileIDToCode;
				hTaskCityMobileIDToCode = hhTaskCityMobileIDToCode;
				hTaskProvMobileIDToCode = hhTaskProvMobileIDToCode;
				hTaskCityProviderIDToCode = hhTaskCityProviderIDToCode;
				hTaskProvProviderIDToCode = hhTaskProvProviderIDToCode;
				hTaskVendorIDToCode = hhTaskVendorIDToCode;

				hTaskHallCore = hhTaskHallCore;
				hTaskCountyMobileCore = hhTaskCountyMobileCore;
				hTaskCityMobileCore = hhTaskCityMobileCore;
				hTaskProvMobileCore = hhTaskProvMobileCore;
				hTaskCityProviderCore = hhTaskCityProviderCore;
				hTaskProvProviderCore = hhTaskProvProviderCore;
				hTaskVendorCore = hhTaskVendorCore;

				hTaskHallDetail = hhTaskHallDetail;
				hTaskCountyMobileDetail = hhTaskCountyMobileDetail;
				hTaskCityMobileDetail = hhTaskCityMobileDetail;
				hTaskProvMobileDetail = hhTaskProvMobileDetail;
				hTaskCityProviderDetail = hhTaskCityProviderDetail;
				hTaskProvProviderDetail = hhTaskProvProviderDetail;
				hTaskVendorDetail = hhTaskVendorDetail;

				hTaskHallReceiverDefine = hhTaskHallReceiverDefine;
				hTaskCountyMobileReceiverDefine = hhTaskCountyMobileReceiverDefine;
				hTaskCityMobileReceiverDefine = hhTaskCityMobileReceiverDefine;
				hTaskProvMobileReceiverDefine = hhTaskProvMobileReceiverDefine;
				hTaskCityProviderReceiverDefine = hhTaskCityProviderReceiverDefine;
				hTaskProvProviderReceiverDefine = hhTaskProvProviderReceiverDefine;
				hTaskVendorReceiverDefine = hhTaskVendorReceiverDefine;

				hTaskHallReceivers = hhTaskHallReceivers;
				hTaskCountyMobileReceivers = hhTaskCountyMobileReceivers;
				hTaskCityMobileReceivers = hhTaskCityMobileReceivers;
				hTaskProvMobileReceivers = hhTaskProvMobileReceivers;
				hTaskCityProviderReceivers = hhTaskCityProviderReceivers;
				hTaskProvProviderReceivers = hhTaskProvProviderReceivers;
				hTaskVendorReceivers = hhTaskVendorReceivers;

				intTaskID = iTaskID + 100;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 重新获取全部零库存消息
	 * @author dyh 2008-01-01
	 */
	public static void ResetZeroDepot() {
		DelZeroDepotAll();
		GetZeroDepot();
	}

	/**
	 * 获取零库存消息
	 * @author dyh 2008-01-01
	 */
	private static void GetZeroDepot() {
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			// 初始化零库存组织信息
			arrZERODEPOT_HALL = new ArrayList[MyConstant.AREA_MAX]; // 厅零库存
			for (int i = 1; i < MyConstant.AREA_MAX; i++) {
				arrZERODEPOT_HALL[i] = new ArrayList<String>(); // 厅零库存
			}
			arrZERODEPOT_CITYPROVIDER = new ArrayList<String>();// 市平台零库存
			arrZERODEPOT_PROVPROVIDER = new ArrayList<String>();// 省平台零库存
			arrZERODEPOT_VENDOR = new ArrayList<String>();// 省平台零库存提醒厂家

			// 获取零库存
			GetZeroDepotOK(MyConstant.ORGTYPE_HALL);
			GetZeroDepotOK(MyConstant.ORGTYPE_CITYPROVIDER);
			GetZeroDepotOK(MyConstant.ORGTYPE_PROVPROVIDER);

			// 删除本次已为非零库存的组织
			for (int i = 1; i < MyConstant.AREA_MAX; i++) {
				ClearZeroDepot(arrZERODEPOT_HALL[i], hZERODEPOT_HALL[i]); // 厅零库存
			}
			ClearZeroDepot(arrZERODEPOT_CITYPROVIDER, hZERODEPOT_CITYPROVIDER);// 市平台零库存
			ClearZeroDepot(arrZERODEPOT_PROVPROVIDER, hZERODEPOT_PROVPROVIDER);// 省平台零库存
			ClearZeroDepot(arrZERODEPOT_VENDOR, hZERODEPOT_VENDOR);// 省平台零库存提醒厂家

			// 置空零库存组织信息
			for (int i = 1; i < MyConstant.AREA_MAX; i++) {
				arrZERODEPOT_HALL[i] = null; // 厅零库存
			}
			arrZERODEPOT_HALL = null;
			arrZERODEPOT_CITYPROVIDER = null;// 市平台零库存
			arrZERODEPOT_PROVPROVIDER = null;// 省平台零库存
			arrZERODEPOT_VENDOR = null;// 省平台零库存提醒厂家
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 获取某组织类型的零库存
	 * @author dyh 2008-01-01
	 * @param strOrgaType
	 */
	private static void GetZeroDepotOK(int intOrgaType) {
		MyJDBC myJDBC = null;
		try {
			myJDBC = new MyJDBC();
			String strSQL = "";
			String strTaskCode = "";
			String strParentTaskCode = "";
			int intParentOrgaType = -1;
			boolean isProProvider = false;

			switch (intOrgaType) {
				// 服务厅零库存
				case MyConstant.ORGTYPE_HALL:
					strSQL = " SELECT OrgaCode,ShortName,ProductName,ParentOrgaCode,AreaID  FROM v_task_zerodepot_hall";
					strTaskCode = Task.ZERODEPOT_HALL;
					strParentTaskCode = Task.ZERODEPOT_HALLTOCITYPROVIDER;
					intParentOrgaType = MyConstant.ORGTYPE_CITYPROVIDER;
					break;
				// 市平台零库存
				case MyConstant.ORGTYPE_CITYPROVIDER:
					strSQL = " SELECT OrgaCode,ShortName,ProductName,ParentOrgaCode,AreaID  FROM v_task_zerodepot_cityprovider";
					strTaskCode = Task.ZERODEPOT_CITYPROVIDER;
					strParentTaskCode = Task.ZERODEPOT_CITYPROVIDERTOPROV;
					intParentOrgaType = MyConstant.ORGTYPE_PROVPROVIDER;
					break;
				// 省平台零库存
				case MyConstant.ORGTYPE_PROVPROVIDER:
					strSQL = " SELECT OrgaCode,ShortName,ProductName,ParentOrgaCode  FROM v_task_zerodepot_provprovider";
					strTaskCode = Task.ZERODEPOT_PROVPROVIDER;
					strParentTaskCode = Task.ZERODEPOT_PROVPROVIDERTOVENDOR;
					intParentOrgaType = MyConstant.ORGTYPE_VENDOR;
					isProProvider = true;
					break;
				default:
					return;
			}
			PreparedStatement ps = myJDBC.prepareStatement(strSQL);
			ResultSet rs = ps.executeQuery();
			String strOrgaCode = "";
			String strOrgaCodeTmp = "";
			String strParentOrgaCodeTmp = "";
			String strShortName = "";
			String strProductName = "";
			String strProductNameToVendor = "";// 为每个厂家设置ProductName
			String strParentOrgaCode = "";
			int intAreaID = 0;
			Map<String, String> hProvProvider = null;

			if (isProProvider)
				hProvProvider = new HashMap<String, String>();

			String isSendSMS = "FALSE";
			while (rs.next()) {
				strOrgaCodeTmp = rs.getString("OrgaCode");
				strParentOrgaCodeTmp = rs.getString("ParentOrgaCode");
				if (strOrgaCodeTmp.equals(strOrgaCode)) {
					if (isProProvider) {
						if (strParentOrgaCodeTmp.equals(strParentOrgaCode))

						{
							strProductNameToVendor += "," + rs.getString("ProductName");
						} else {
							hProvProvider.put(strShortName + "`" + strParentOrgaCode, strProductNameToVendor);
							strProductNameToVendor = rs.getString("ProductName");
							strParentOrgaCode = strParentOrgaCodeTmp;
						}
					}
					strProductName += "," + rs.getString("ProductName");
				} else {
					if (strOrgaCode.length() > 0 && strParentOrgaCode.length() > 0) {
						isSendSMS = CheckZeroDepot(intAreaID, strOrgaCode, strTaskCode, strProductName);
						InsertTaskOK(intAreaID, strOrgaCode, intOrgaType, strTaskCode, strProductName, isSendSMS, strShortName, "CTMS");

						if (!isProProvider)
							InsertTaskOK(intAreaID, strParentOrgaCode, intParentOrgaType, strParentTaskCode, strProductName + "`" + strShortName,
									isSendSMS, strShortName, "CTMS");
					}
					strOrgaCode = strOrgaCodeTmp;
					strParentOrgaCode = strParentOrgaCodeTmp;
					strProductName = rs.getString("ProductName");
					strProductNameToVendor = strProductName;
					strShortName = rs.getString("ShortName");

					if (MyConstant.ORGTYPE_HALL == intOrgaType || MyConstant.ORGTYPE_CITYPROVIDER == intOrgaType) {
						intAreaID = rs.getInt("AreaID");
					}
				}
			}
			if (strOrgaCode.length() > 0) {
				isSendSMS = CheckZeroDepot(intAreaID, strOrgaCode, strTaskCode, strProductName);
				InsertTaskOK(intAreaID, strOrgaCode, intOrgaType, strTaskCode, strProductName, isSendSMS, strShortName, "CTMS");

				if (!isProProvider)
					InsertTaskOK(intAreaID, strParentOrgaCode, intParentOrgaType, strParentTaskCode, strProductName + "`" + strShortName, isSendSMS,
							strShortName, "CTMS");
				else {
					hProvProvider.put(strShortName + "`" + strParentOrgaCode, strProductNameToVendor);

					// 省平台发给厂家的零库存警告
					// hProvProvider->key： strOrgaCode+"`"+strShortName+"`"+strParentOrgaCode
					// ->value:strProductNameToVendor
					String key = null;
					String val = "";
					Iterator<Entry<String, String>> iter = hProvProvider.entrySet().iterator();
					while (iter.hasNext()) {
						Entry<String, String> entry = iter.next();
						key = entry.getKey();
						val = entry.getValue();
						int i = key.indexOf("`");
						strShortName = key.substring(0, i);
						strParentOrgaCode = key.substring(i + 1);
						InsertTaskOK(0, strParentOrgaCode, intParentOrgaType, strParentTaskCode, val + "`" + strShortName, CheckZeroDepot(0,
								strParentOrgaCode + strShortName, strParentTaskCode, val), strShortName, "CTMS");
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			MyJDBC.close(myJDBC);
		}
	}

	/**
	 * 如果是重复的零库存信息，则不给用户发送手机短信（网站内消息依然发送）。
	 * @author dyh 2008-01-01
	 * @param intReceiverAreaID
	 * @param strOrgaCode
	 * @param strTaskCode
	 * @param strProductName
	 * @return "TRUE"表示发送；"FALSE"表示不发送
	 */
	private static String CheckZeroDepot(int intReceiverAreaID, String strOrgaCode, String strTaskCode, String strProductName) {
		try {
			Map<String, String> hZeroDepot = new HashMap<String, String>();
			ArrayList<String> arrZeroDepot = new ArrayList<String>();

			if (Task.ZERODEPOT_HALL.equals(strTaskCode)) {
				hZeroDepot = hZERODEPOT_HALL[intReceiverAreaID];
				arrZeroDepot = arrZERODEPOT_HALL[intReceiverAreaID];
			} else if (Task.ZERODEPOT_CITYPROVIDER.equals(strTaskCode)) {
				hZeroDepot = hZERODEPOT_CITYPROVIDER;
				arrZeroDepot = arrZERODEPOT_CITYPROVIDER;
			} else if (Task.ZERODEPOT_PROVPROVIDER.equals(strTaskCode)) {
				hZeroDepot = hZERODEPOT_PROVPROVIDER;
				arrZeroDepot = arrZERODEPOT_PROVPROVIDER;
			} else if (Task.ZERODEPOT_PROVPROVIDERTOVENDOR.equals(strTaskCode)) {
				hZeroDepot = hZERODEPOT_VENDOR;
				arrZeroDepot = arrZERODEPOT_VENDOR;
			} else
				return "FALSE";

			arrZeroDepot.add(strOrgaCode);

			String oProductName = hZeroDepot.get(strOrgaCode);
			if (oProductName != null && strProductName.equals(oProductName))
				return "FALSE";
			else {
				hZeroDepot.put(strOrgaCode, strProductName);
				return "TRUE";
			}

		} catch (Exception e) {
			e.printStackTrace();
			return "FALSE";
		}
	}

	/**
	 * 清除本次非零库存的组织
	 * @author dyh 2008-01-01
	 * @param arrZeroDepot
	 * @param hZeroDepot
	 */
	private static void ClearZeroDepot(ArrayList<String> arrZeroDepot, Map<String, String> hZeroDepot) {
		try {
			String key = null;
			Iterator<Entry<String, String>> iter = hZeroDepot.entrySet().iterator();
			ArrayList<String> arrRemove = new ArrayList<String>();
			int i = 0;
			boolean found = false;
			while (iter.hasNext()) {
				found = false;
				Entry<String, String> entry = iter.next();
				key = entry.getKey();
				for (i = 0; i < arrZeroDepot.size(); i++) {
					if (arrZeroDepot.contains(key)) {
						found = true;
						break;
					}
				}
				if (!found)
					arrRemove.add(key);
			}
			for (i = 0; i < arrRemove.size(); i++) {
				hZeroDepot.remove(arrRemove.get(i));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除零库存消息
	 * @author dyh 2008-01-01
	 * @param intAreaID
	 * @param strTaskCode
	 */
	private static void DelZeroDepot(int intAreaID, String strTaskCode) {
		try {
			int intOrgaType = MyFormat.formatInt(Task.hTaskDefineReceiverOrgaType.get(strTaskCode));
			if (intOrgaType <= 0)
				return;

			Map<String, String> hTaskIDToCode = new HashMap<String, String>();
			Map<String, String> hTaskCore = new HashMap<String, String>();
			Map<String, String> hTaskDetail = new HashMap<String, String>();
			Map<String, String> hTaskReceiverDefine = new HashMap<String, String>();
			Map<String, String> hTaskReceivers = new HashMap<String, String>();
			Map<String, String> hTaskSendTime = new HashMap<String, String>();

			switch (intOrgaType) {
				case MyConstant.ORGTYPE_HALL:
					hTaskIDToCode = hTaskHallIDToCode[intAreaID];
					hTaskCore = hTaskHallCore[intAreaID];
					hTaskDetail = hTaskHallDetail[intAreaID];
					hTaskReceiverDefine = hTaskHallReceiverDefine;
					hTaskReceivers = hTaskHallReceivers[intAreaID];
					break;
				case MyConstant.ORGTYPE_PROVPROVIDER:
					hTaskIDToCode = hTaskProvProviderIDToCode;
					hTaskCore = hTaskProvProviderCore;
					hTaskDetail = hTaskProvProviderDetail;
					hTaskReceiverDefine = hTaskProvProviderReceiverDefine;
					hTaskReceivers = hTaskProvProviderReceivers;
					break;
				case MyConstant.ORGTYPE_CITYPROVIDER:
					hTaskIDToCode = hTaskCityProviderIDToCode[intAreaID];
					hTaskCore = hTaskCityProviderCore[intAreaID];
					hTaskDetail = hTaskCityProviderDetail[intAreaID];
					hTaskReceiverDefine = hTaskCityProviderReceiverDefine;
					hTaskReceivers = hTaskCityProviderReceivers[intAreaID];
					break;
				case MyConstant.ORGTYPE_VENDOR:
					hTaskIDToCode = hTaskVendorIDToCode;
					hTaskCore = hTaskVendorCore;
					hTaskDetail = hTaskVendorDetail;
					hTaskReceiverDefine = hTaskVendorReceiverDefine;
					hTaskReceivers = hTaskVendorReceivers;
					break;
				default:
					return;
			}
			if (hTaskIDToCode == null || hTaskIDToCode.size() == 0)
				return;

			String key = null;
			String val = "";
			Iterator<Entry<String, String>> iter = hTaskIDToCode.entrySet().iterator();
			ArrayList<String> arrKey = new ArrayList<String>();
			while (iter.hasNext()) {
				Entry<String, String> entry = iter.next();
				key = entry.getKey();
				val = entry.getValue();
				if (strTaskCode.equals(val)) {
					arrKey.add(key);
					hTaskCore.remove(key);
					hTaskDetail.remove(key);
					hTaskReceiverDefine.remove(key);
					hTaskReceivers.remove(key);
					hTaskSendTime.remove(key);
				}
			}
			for (int i = 0; i < arrKey.size(); i++)
				hTaskIDToCode.remove(arrKey.get(i));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除所有零库存消息
	 * @author dyh 2008-01-01
	 */
	public static void DelZeroDepotAll() {
		for (int i = 1; i < MyConstant.AREA_MAX; i++) {
			DelZeroDepot(i, ZERODEPOT_HALL);
			DelZeroDepot(i, ZERODEPOT_HALLTOCITYPROVIDER);
			DelZeroDepot(i, ZERODEPOT_CITYPROVIDER);
			DelZeroDepot(i, ZERODEPOT_CITYPROVIDERTOPROV);
		}
		DelZeroDepot(0, ZERODEPOT_PROVPROVIDER);
		DelZeroDepot(0, ZERODEPOT_PROVPROVIDERTOVENDOR);
	}

	/**
	 * 设置网页定时弹出警告框消息（主要用于发布维护前的提醒用户下线等消息）
	 * @author dyh 2008-01-01
	 * @param strOrgaType
	 * @param sAlert
	 * @param noAlert true:只有top提示，没有alert警告框；false：两者都有
	 */
	public static void setAlert(String strOrgaType, String sAlert, boolean noAlert) {
		if (strOrgaType != null && strOrgaType.length() > 0 && sAlert != null && sAlert.length() > 0) {
			if (strOrgaType.endsWith(","))
				strOrgaType = strOrgaType.substring(0, strOrgaType.length() - 1);
			int orgatype = -1;
			if (strOrgaType.indexOf(",") < 0) {
				orgatype = Integer.parseInt(strOrgaType);
				if (orgatype == -1) {
					for (int j = 0; j < Alerts.length; j++)
						Alerts[j] = sAlert;
				} else if (orgatype < Alerts.length && orgatype >= 0) {
					Alerts[orgatype] = sAlert;
					AlertTypes[orgatype] = noAlert;
				}
				return;
			}
			String strOrgaTypes[] = strOrgaType.split(",");
			for (int i = 0; i < strOrgaTypes.length; i++) {
				orgatype = Integer.parseInt(strOrgaTypes[i]);
				if (orgatype == -1) {
					for (int j = 0; j < Alerts.length; j++)
						Alerts[j] = sAlert;
					return;
				} else if (orgatype < Alerts.length && orgatype >= 0) {
					Alerts[orgatype] = sAlert;
					AlertTypes[orgatype] = noAlert;
				}
			}
		}
	}

	/**
	 * 清除提醒用户的警告消息框
	 * @author dyh 2008-01-01
	 * @param strOrgaType -1表示全部
	 */
	public static void clearAlert(String strOrgaType) {
		if (strOrgaType != null && strOrgaType.length() > 0) {
			if (strOrgaType.endsWith(","))
				strOrgaType = strOrgaType.substring(0, strOrgaType.length() - 1);
			int orgatype = -1;
			int i = 0;
			if (strOrgaType.indexOf(",") < 0) {
				orgatype = Integer.parseInt(strOrgaType);
				if (orgatype == -1) {
					for (i = 0; i < Alerts.length; i++) {
						Alerts[i] = "";
					}
					return;
				} else if (orgatype < Alerts.length && orgatype >= 0)
					Alerts[orgatype] = "";
				return;
			}
			String strOrgaTypes[] = strOrgaType.split(",");
			for (i = 0; i < strOrgaTypes.length; i++) {
				orgatype = Integer.parseInt(strOrgaTypes[i]);
				if (orgatype == -1) {
					for (int j = 0; j < Alerts.length; j++)
						Alerts[j] = "";
					return;
				} else if (orgatype < Alerts.length && orgatype >= 0)
					Alerts[orgatype] = "";
			}
		}
	}

	/**
	 * ZSMS启动5分钟后，才能运行定时器程序(ContextListener.java)
	 * @author dyh 2008-01-01
	 * @return
	 */
	public static boolean TaskCanBegin() {
		boolean isOK = false;
		if (CTMSStartTime != null) {
			Date now = Calendar.getInstance().getTime();
			if ((now.getTime() - Task.CTMSStartTime.getTime()) >= 120000)
				isOK = true;
		}
		return isOK;
	}

	/**
	 * 限制短信在规定时间段内发送
	 * @author dyh 2011-01-05
	 * @return
	 */
	public static boolean canSendSMS() {
		String time = MyFormat.getCurrentTime();
		int hour = Integer.parseInt(time.substring(0, 2));
		return (hour >= SMSStartTime && hour <= SMSEndTime);
	}
}
